summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2017-11-13 23:52:50 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2017-11-13 23:52:50 +0000
commit6c5f54722f550753f917210df006a811ceb4ea04 (patch)
treef3db16e28c25f134a7ce5d3736e6d508c89fe935 /sys/kern
parent0731ebd7182102756256999a6ec042c57581d190 (diff)
add taskq_barrier
taskq_barrier guarantees that any task that was running on the taskq has finished by the time taskq_barrier returns. it is similar to intr_barrier. this is needed for use in ifq_barrier as part of an upcoming change.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_task.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/sys/kern/kern_task.c b/sys/kern/kern_task.c
index cd7e2a436f4..feaa7bed5cd 100644
--- a/sys/kern/kern_task.c
+++ b/sys/kern/kern_task.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_task.c,v 1.20 2017/10/30 14:01:42 visa Exp $ */
+/* $OpenBSD: kern_task.c,v 1.21 2017/11/13 23:52:49 dlg Exp $ */
/*
* Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
@@ -22,6 +22,7 @@
#include <sys/mutex.h>
#include <sys/kthread.h>
#include <sys/task.h>
+#include <sys/proc.h>
#define TASK_ONQUEUE 1
@@ -68,6 +69,7 @@ struct taskq *const systqmp = &taskq_sys_mp;
void taskq_init(void); /* called in init_main.c */
void taskq_create_thread(void *);
+void taskq_barrier_task(void *);
int taskq_sleep(const volatile void *, struct mutex *, int,
const char *, int);
int taskq_next_work(struct taskq *, struct task *, sleepfn);
@@ -179,6 +181,30 @@ taskq_create_thread(void *arg)
}
void
+taskq_barrier(struct taskq *tq)
+{
+ struct sleep_state sls;
+ unsigned int notdone = 1;
+ struct task t = TASK_INITIALIZER(taskq_barrier_task, &notdone);
+
+ task_add(tq, &t);
+
+ while (notdone) {
+ sleep_setup(&sls, &notdone, PWAIT, "tqbar");
+ sleep_finish(&sls, notdone);
+ }
+}
+
+void
+taskq_barrier_task(void *p)
+{
+ unsigned int *notdone = p;
+
+ *notdone = 0;
+ wakeup_one(notdone);
+}
+
+void
task_set(struct task *t, void (*fn)(void *), void *arg)
{
t->t_func = fn;