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)The wmesg argument specifies a string of no more than 8 characters that describes the resource orcondition associated with the CV. The kernel does not use this argument directly but makes it availablefor utilities such as ps(1) to display.cv_destroy(cv)Release resources used by a CV. The CV must not be in use when it is destroyed, and must not beused afterwards.cv_wait(cv , mtx)Cause the current LWP to wait non-interruptably for access to a resource, or for an I/O operation tocomplete. The LWPwill resume execution when awoken byanother thread using cv_signal() orcv_broadcast().mtx specifies a kernel mutex tobeused as an interlock, and must be held by the calling LWP on entryto cv_wait(). It will be released once the LWP has prepared to sleep, and will be reacquired beforecv_wait() returns.Asmall window exists between testing for availability of a resource and waiting for the resource withcv_wait(), in which the resource may become available again. The interlock is used to guarenteethat the resource will not be signalled as available until the calling LWP has begun to wait for it.Non-interruptable waits have the potential to deadlock the system, and so must be kept short (typically,under one second).cv_wait_sig(cv , mtx)As per cv_wait(), but causes the current LWP to wait interruptably. Ifthe LWP recieves asignal, oris interrupted by another condition such as its containing process exiting, the wait is ended early andan error code returned.If cv_wait_sig() returns as a result of a signal, the return value is ERESTART if the signal has theSA_RESTART property. Ifawoken normally, the value is zero, and EINTR under all other conditions.cv_timedwait(cv , mtx , ticks)As per cv_wait(), but will return early if a timeout specified by the ticks argument expires.ticks is an architecture and system dependent value related to the number of clock interrupts persecond. See hz(9) for details. The mstohz(9) macro can be used to convert a timeout expressed inmilliseconds to one suitable for cv_timedwait(). If the ticks argument is zero,cv_timedwait() behaves exactly like cv_wait().If the timeout expires before the LWP is awoken, the return value is EWOULDBLOCK. Ifawoken normally,the return value is zero.cv_timedwait_sig(cv , mtx , ticks)As per cv_wait_sig(), but also accepts a timeout value and will return EWOULDBLOCK if thetimeout expires.cv_signal(cv)Aw aken one LWP (potentially among many) that is waiting on the specified condition variable. Themutex passed to the wait function ( mtx )must also be held when calling cv_signal().(Note that cv_signal() is erroneously named in that it does not send a signal in the traditionalsense to LWPs waiting on a CV.)<strong>NetBSD</strong> 3.0 June 4, 2008 2

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

Saved successfully!

Ooh no, something went wrong!