12.07.2015 Views

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CONDVAR(9) <strong>NetBSD</strong> <strong>Kernel</strong> Developer’s <strong>Manual</strong> CONDVAR(9)cv_broadcast(cv)Aw aken all LWPs waiting on the specified condition variable. The mutex passed to the wait function( mtx )must also be held when calling cv_broadcast().cv_has_waiters(cv)Return true if one or more LWPs are waiting on the specified condition variable.cv_has_waiters() cannot test reliably for interruptable waits. It should only be used to test fornon-interruptable waits made using cv_wait().cv_has_waiters() should only be used when making diagnostic assertions, and must be calledwhile holding the interlocking mutex passed to cv_wait().EXAMPLESConsuming a resource:/∗∗ Lock the resource. Its mutex will also serve as the∗ interlock.∗/mutex_enter(&res->mutex);/∗∗ Wait for the resource to become available.∗/while (res->state == BUSY)cv_wait(&res->condvar, &res->mutex);/∗∗ It’s now available to us.∗ resource, and consume it.∗/res->state = BUSY;mutex_exit(&res->mutex);consume(res);Take ownership of theReleasing a resource for the next consumer to use:mutex_enter(&res->mutex);res->state = IDLE;cv_signal(&res->condvar);mutex_exit(&res->mutex);CODE REFERENCESThis section describes places within the <strong>NetBSD</strong> source tree where code implementing condition variablescan be found. All pathnames are relative to /usr/src.The core of the CV implementation is in sys/kern/kern_condvar.c.The header file sys/sys/condvar.h describes the public interface.<strong>NetBSD</strong> 3.0 June 4, 2008 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!