COND_INIT(9) Kernel Developer's Manual COND_INIT(9)

cond_init, cond_wait, cond_signal, COND_INITIALIZERwait condition API

#include <sys/systm.h>

cond_init(struct cond *c);

cond_wait(struct cond *c, const char *wmesg);

cond_signal(struct cond *c);


The wait condition API allows a thread to sleep while it waits for a notification, aka signal, that pending work has completed.

() initialises the wait condition c for use.

() is used to sleep on the wait condition c until whatever the thread is waiting on calls cond_signal(). wmesg is a pointer to a character string indicating the reason the thread is sleeping.

() is used to notify the thread waiting on c that the work has finished and it may proceed.

() initialises a declaration of a cond for use.

cond_init(), and cond_signal() can be called during autoconf, from process context, or from interrupt context.

cond_wait() can be called from process context.

taskq_barrier(9) is implemented using the wait condition API. The following is a commented copy of the implementation:

static void	taskq_barrier_task(void *);

taskq_barrier(struct taskq *tq)
	struct cond c;
	struct task t;

	 * any currently running work has to have finished
	 * before this new task can be run.

	task_init(&t, taskq_barrier_task, &c);

	task_add(tq, &t);

	/* wait until the task runs and signals completion */
	cond_wait(&c, "tqbar");

static void
taskq_barrier_task(void *p)
	struct cond *c = p;

	 * all previous tasks have run, signal the thread waiting
	 * in taskq_barrier

March 11, 2022 OpenBSD 7.5