logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

condvar, cv_init, cv_destroy, cv_wait, cv_wait_sig, cv_wait_unlock, cv_timedwait, cv_timedwait_sbt,

Description

       Condition  variables  are  used  in  conjunction with mutexes to wait for conditions to occur.  Condition
       variables are created with cv_init(), where cvp is a pointer to space for a structcv,  and  desc  is  a
       pointer to a null-terminated character string that describes the condition variable.  Condition variables
       are   destroyed   with   cv_destroy().   Threads  wait  on  condition  variables  by  calling  cv_wait(),
       cv_wait_sig(), cv_wait_unlock(), cv_timedwait(),  or  cv_timedwait_sig().   Threads  unblock  waiters  by
       calling cv_signal() to unblock one waiter, or cv_broadcast() or cv_broadcastpri() to unblock all waiters.
       In  addition  to  waking waiters, cv_broadcastpri() ensures that all of the waiters have a priority of at
       least pri by raising the priority of any threads that do not.  cv_wmesg() returns the description  string
       of cvp, as set by the initial call to cv_init().

       The  lock argument is a pointer to either a mutex(9), rwlock(9), or sx(9) lock.  A mutex(9) argument must
       be initialized with MTX_DEF and not  MTX_SPIN.   A  thread  must  hold  lock  before  calling  cv_wait(),
       cv_wait_sig(),  cv_wait_unlock(),  cv_timedwait(),  or  cv_timedwait_sig().   When  a  thread  waits on a
       condition, lock is atomically released before the thread is blocked, then reacquired before the  function
       call returns.  In addition, the thread will fully drop the Giant mutex (even if recursed) while the it is
       suspended  and will reacquire the Giant mutex before the function returns.  The cv_wait_unlock() function
       does not reacquire the lock before returning.  Note that the  Giant  mutex  may  be  specified  as  lock.
       However, Giant may not be used as lock for the cv_wait_unlock() function.  All waiters must pass the same
       lock in conjunction with cvp.

       When  cv_wait(),  cv_wait_sig(),  cv_wait_unlock(), cv_timedwait(), and cv_timedwait_sig() unblock, their
       calling threads are made runnable.  cv_timedwait() and cv_timedwait_sig() wait for  at  most  timo  /  HZ
       seconds  before  being  unblocked and returning EWOULDBLOCK; otherwise, they return 0.  cv_wait_sig() and
       cv_timedwait_sig() return prematurely with a value of EINTR or ERESTART if a signal is caught,  or  0  if
       signaled via cv_signal() or cv_broadcast().

       cv_timedwait_sbt()  and cv_timedwait_sig_sbt() functions take sbt argument instead of timo.  It allows to
       specify relative or absolute unblock time with higher resolution in form of sbintime_t.  The parameter pr
       allows to specify wanted absolute event  precision.   The  parameter  flags  allows  to  pass  additional
       callout_reset_sbt() flags.

Errors

cv_wait_sig() and cv_timedwait_sig() will fail if:

       [EINTR]            A signal was caught and the system call should be interrupted.

       [ERESTART]         A signal was caught and the system call should be restarted.

       cv_timedwait() and cv_timedwait_sig() will fail if:

       [EWOULDBLOCK]      Timeout expired.

Name

       condvar,  cv_init,  cv_destroy,  cv_wait,  cv_wait_sig,  cv_wait_unlock,  cv_timedwait, cv_timedwait_sbt,
       cv_timedwait_sig, cv_timedwait_sig_sbt,  cv_signal,  cv_broadcast,  cv_broadcastpri,  cv_wmesg  —  kernel
       condition variable

Return Values

       If  successful,  cv_wait_sig(),  cv_timedwait(),  and cv_timedwait_sig() return 0.  Otherwise, a non-zero
       error code is returned.

       cv_wmesg() returns the description string that was passed to cv_init().

See Also

locking(9), mtx_pool(9), mutex(9), rwlock(9), sema(9), sleep(9), sx(9), timeout(9)

Debian                                          February 19, 2013                                     CONDVAR(9)

Synopsis

#include<sys/param.h>#include<sys/proc.h>#include<sys/condvar.h>voidcv_init(structcv*cvp, constchar*desc);

       voidcv_destroy(structcv*cvp);

       voidcv_wait(structcv*cvp, lock);

       intcv_wait_sig(structcv*cvp, lock);

       voidcv_wait_unlock(structcv*cvp, lock);

       intcv_timedwait(structcv*cvp, lock, inttimo);

       intcv_timedwait_sbt(structcv*cvp, lock, sbintime_tsbt, sbintime_tpr, intflags);

       intcv_timedwait_sig(structcv*cvp, lock, inttimo);

       intcv_timedwait_sig_sbt(structcv*cvp, lock, sbintime_tsbt, sbintime_tpr, intflags);

       voidcv_signal(structcv*cvp);

       voidcv_broadcast(structcv*cvp);

       voidcv_broadcastpri(structcv*cvp, intpri);

       constchar*cv_wmesg(structcv*cvp);

See Also