Apache2
Condition Variable Routines
Collaboration diagram for Condition Variable Routines:

Typedefs

typedef struct apr_thread_cond_t apr_thread_cond_t
 

Functions

apr_status_t apr_thread_cond_create (apr_thread_cond_t **cond, apr_pool_t *pool)
 
apr_status_t apr_thread_cond_wait (apr_thread_cond_t *cond, apr_thread_mutex_t *mutex)
 
apr_status_t apr_thread_cond_timedwait (apr_thread_cond_t *cond, apr_thread_mutex_t *mutex, apr_interval_time_t timeout)
 
apr_status_t apr_thread_cond_signal (apr_thread_cond_t *cond)
 
apr_status_t apr_thread_cond_broadcast (apr_thread_cond_t *cond)
 
apr_status_t apr_thread_cond_destroy (apr_thread_cond_t *cond)
 
 APR_POOL_DECLARE_ACCESSOR (thread_cond)
 

Detailed Description

Typedef Documentation

◆ apr_thread_cond_t

Opaque structure for thread condition variables

Function Documentation

◆ APR_POOL_DECLARE_ACCESSOR()

APR_POOL_DECLARE_ACCESSOR ( thread_cond  )

Get the pool used by this thread_cond.

Returns
apr_pool_t the pool

◆ apr_thread_cond_broadcast()

apr_status_t apr_thread_cond_broadcast ( apr_thread_cond_t cond)

Signals all threads blocking on the given condition variable. Each thread that was signaled is then scheduled to wake up and acquire the associated mutex. This will happen in a serialized manner.

Parameters
condthe condition variable on which to produce the broadcast.
Remarks
If no threads are waiting on the condition variable, nothing happens.

◆ apr_thread_cond_create()

apr_status_t apr_thread_cond_create ( apr_thread_cond_t **  cond,
apr_pool_t pool 
)

Note: destroying a condition variable (or likewise, destroying or clearing the pool from which a condition variable was allocated) if any threads are blocked waiting on it gives undefined results. Create and initialize a condition variable that can be used to signal and schedule threads in a single process.

Parameters
condthe memory address where the newly created condition variable will be stored.
poolthe pool from which to allocate the condition.

◆ apr_thread_cond_destroy()

apr_status_t apr_thread_cond_destroy ( apr_thread_cond_t cond)

Destroy the condition variable and free the associated memory.

Parameters
condthe condition variable to destroy.

◆ apr_thread_cond_signal()

apr_status_t apr_thread_cond_signal ( apr_thread_cond_t cond)

Signals a single thread, if one exists, that is blocking on the given condition variable. That thread is then scheduled to wake up and acquire the associated mutex. Although it is not required, if predictable scheduling is desired, that mutex must be locked while calling this function.

Parameters
condthe condition variable on which to produce the signal.
Remarks
If no threads are waiting on the condition variable, nothing happens.

◆ apr_thread_cond_timedwait()

apr_status_t apr_thread_cond_timedwait ( apr_thread_cond_t cond,
apr_thread_mutex_t mutex,
apr_interval_time_t  timeout 
)

Put the active calling thread to sleep until signaled to wake up or the timeout is reached. Each condition variable must be associated with a mutex, and that mutex must be locked before calling this function, or the behavior will be undefined. As the calling thread is put to sleep, the given mutex will be simultaneously released; and as this thread wakes up the lock is again simultaneously acquired.

Parameters
condthe condition variable on which to block.
mutexthe mutex that must be locked upon entering this function, is released while the thread is asleep, and is again acquired before returning from this function.
timeoutThe amount of time in microseconds to wait. This is a maximum, not a minimum. If the condition is signaled, we will wake up before this time, otherwise the error APR_TIMEUP is returned.

◆ apr_thread_cond_wait()

apr_status_t apr_thread_cond_wait ( apr_thread_cond_t cond,
apr_thread_mutex_t mutex 
)

Put the active calling thread to sleep until signaled to wake up. Each condition variable must be associated with a mutex, and that mutex must be locked before calling this function, or the behavior will be undefined. As the calling thread is put to sleep, the given mutex will be simultaneously released; and as this thread wakes up the lock is again simultaneously acquired.

Parameters
condthe condition variable on which to block.
mutexthe mutex that must be locked upon entering this function, is released while the thread is asleep, and is again acquired before returning from this function.
Remarks
Spurious wakeups may occur. Before and after every call to wait on a condition variable, the caller should test whether the condition is already met.