Xenomai
3.0.5
|
Cobalt/POSIX condition variable services. More...
Functions | |
int | pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) |
Initialize a condition variable. More... | |
int | pthread_cond_destroy (pthread_cond_t *cond) |
Destroy a condition variable. More... | |
int | pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) |
Wait on a condition variable. More... | |
int | pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) |
Wait a bounded time on a condition variable. More... | |
int | pthread_cond_signal (pthread_cond_t *cond) |
Signal a condition variable. More... | |
int | pthread_cond_broadcast (pthread_cond_t *cond) |
Broadcast a condition variable. More... | |
int | pthread_condattr_init (pthread_condattr_t *attr) |
Initialize a condition variable attributes object. More... | |
int | pthread_condattr_destroy (pthread_condattr_t *attr) |
Destroy a condition variable attributes object. More... | |
int | pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clk_id) |
Get the clock selection attribute from a condition variable attributes object. More... | |
int | pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clk_id) |
Set the clock selection attribute of a condition variable attributes object. More... | |
int | pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared) |
Get the process-shared attribute from a condition variable attributes object. More... | |
int | pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared) |
Set the process-shared attribute of a condition variable attributes object. More... | |
Cobalt/POSIX condition variable services.
A condition variable is a synchronization object that allows threads to suspend execution until some predicate on shared data is satisfied. The basic operations on conditions are: signal the condition (when the predicate becomes true), and wait for the condition, suspending the thread execution until another thread signals the condition.
A condition variable must always be associated with a mutex, to avoid the race condition where a thread prepares to wait on a condition variable and another thread signals the condition just before the first thread actually waits on it.
Before it can be used, a condition variable has to be initialized with pthread_cond_init(). An attribute object, which reference may be passed to this service, allows to select the features of the created condition variable, namely the clock used by the pthread_cond_timedwait() service (CLOCK_REALTIME is used by default), and whether it may be shared between several processes (it may not be shared by default, see pthread_condattr_setpshared()).
Note that only pthread_cond_init() may be used to initialize a condition variable, using the static initializer PTHREAD_COND_INITIALIZER is not supported.
int pthread_cond_broadcast | ( | pthread_cond_t * | cond | ) |
Broadcast a condition variable.
This service unblocks all threads blocked on the condition variable cnd.
cond | the condition variable to be signalled. |
int pthread_cond_destroy | ( | pthread_cond_t * | cond | ) |
Destroy a condition variable.
This service destroys the condition variable cond, if no thread is currently blocked on it. The condition variable becomes invalid for all condition variable services (they all return the EINVAL error) except pthread_cond_init().
cond | the condition variable to be destroyed. |
int pthread_cond_init | ( | pthread_cond_t * | cond, |
const pthread_condattr_t * | attr | ||
) |
Initialize a condition variable.
This service initializes the condition variable cond, using the condition variable attributes object attr. If attr is NULL, default attributes are used (see pthread_condattr_init()).
cond | the condition variable to be initialized; |
attr | the condition variable attributes object. |
int pthread_cond_signal | ( | pthread_cond_t * | cond | ) |
Signal a condition variable.
This service unblocks one thread blocked on the condition variable cnd.
If more than one thread is blocked on the specified condition variable, the highest priority thread is unblocked.
cond | the condition variable to be signalled. |
int pthread_cond_timedwait | ( | pthread_cond_t * | cond, |
pthread_mutex_t * | mutex, | ||
const struct timespec * | abstime | ||
) |
Wait a bounded time on a condition variable.
This service is equivalent to pthread_cond_wait(), except that the calling thread remains blocked on the condition variable cnd only until the timeout specified by abstime expires.
The timeout abstime is expressed as an absolute value of the clock attribute passed to pthread_cond_init(). By default, CLOCK_REALTIME is used.
cond | the condition variable to wait for; |
mutex | the mutex associated with cnd; |
abstime | the timeout, expressed as an absolute value of the clock attribute passed to pthread_cond_init(). |
int pthread_cond_wait | ( | pthread_cond_t * | cond, |
pthread_mutex_t * | mutex | ||
) |
Wait on a condition variable.
This service atomically unlocks the mutex mx, and block the calling thread until the condition variable cnd is signalled using pthread_cond_signal() or pthread_cond_broadcast(). When the condition is signaled, this service re-acquire the mutex before returning.
Spurious wakeups occur if a signal is delivered to the blocked thread, so, an application should not assume that the condition changed upon successful return from this service.
Even if the mutex mx is recursive and its recursion count is greater than one on entry, it is unlocked before blocking the caller, and the recursion count is restored once the mutex is re-acquired by this service before returning.
Once a thread is blocked on a condition variable, a dynamic binding is formed between the condition vairable cnd and the mutex mx; if another thread calls this service specifying cnd as a condition variable but another mutex than mx, this service returns immediately with the EINVAL status.
This service is a cancellation point for Cobalt threads (created with the pthread_create() service). When such a thread is cancelled while blocked in a call to this service, the mutex mx is re-acquired before the cancellation cleanup handlers are called.
cond | the condition variable to wait for; |
mutex | the mutex associated with cnd. |
int pthread_condattr_destroy | ( | pthread_condattr_t * | attr | ) |
Destroy a condition variable attributes object.
This service destroys the condition variable attributes object attr. The object becomes invalid for all condition variable services (they all return EINVAL) except pthread_condattr_init().
attr | the initialized mutex attributes object to be destroyed. |
int pthread_condattr_getclock | ( | const pthread_condattr_t * | attr, |
clockid_t * | clk_id | ||
) |
Get the clock selection attribute from a condition variable attributes object.
This service stores, at the address clk_id, the value of the clock attribute in the condition variable attributes object attr.
See pthread_cond_timedwait() for a description of the effect of this attribute on a condition variable. The clock ID returned is CLOCK_REALTIME or CLOCK_MONOTONIC.
attr | an initialized condition variable attributes object, |
clk_id | address where the clock attribute value will be stored on success. |
int pthread_condattr_getpshared | ( | const pthread_condattr_t * | attr, |
int * | pshared | ||
) |
Get the process-shared attribute from a condition variable attributes object.
This service stores, at the address pshared, the value of the pshared attribute in the condition variable attributes object attr.
The pshared attribute may only be one of PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED. See pthread_condattr_setpshared() for the meaning of these two constants.
attr | an initialized condition variable attributes object. |
pshared | address where the value of the pshared attribute will be stored on success. |
int pthread_condattr_init | ( | pthread_condattr_t * | attr | ) |
Initialize a condition variable attributes object.
This services initializes the condition variable attributes object attr with default values for all attributes. Default value are:
If this service is called specifying a condition variable attributes object that was already initialized, the attributes object is reinitialized.
attr | the condition variable attributes object to be initialized. |
int pthread_condattr_setclock | ( | pthread_condattr_t * | attr, |
clockid_t | clk_id | ||
) |
Set the clock selection attribute of a condition variable attributes object.
This service set the clock attribute of the condition variable attributes object attr.
See pthread_cond_timedwait() for a description of the effect of this attribute on a condition variable.
attr | an initialized condition variable attributes object, |
clk_id | value of the clock attribute, may be CLOCK_REALTIME or CLOCK_MONOTONIC. |
int pthread_condattr_setpshared | ( | pthread_condattr_t * | attr, |
int | pshared | ||
) |
Set the process-shared attribute of a condition variable attributes object.
This service set the pshared attribute of the condition variable attributes object attr.
attr | an initialized condition variable attributes object. |
pshared | value of the pshared attribute, may be one of:
|