RTS API Documentation  1.10.11
Typedefs | Functions
Condition Variable Routines
+ Collaboration diagram for Condition Variable Routines:

Typedefs

typedef struct fspr_thread_cond_t switch_thread_cond_t
 

Functions

switch_status_t switch_thread_cond_create (switch_thread_cond_t **cond, switch_memory_pool_t *pool)
 
switch_status_t switch_thread_cond_wait (switch_thread_cond_t *cond, switch_mutex_t *mutex)
 
switch_status_t switch_thread_cond_timedwait (switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout)
 
switch_status_t switch_thread_cond_signal (switch_thread_cond_t *cond)
 
switch_status_t switch_thread_cond_broadcast (switch_thread_cond_t *cond)
 
switch_status_t switch_thread_cond_destroy (switch_thread_cond_t *cond)
 

Detailed Description

Typedef Documentation

◆ switch_thread_cond_t

typedef struct fspr_thread_cond_t switch_thread_cond_t

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.Opaque structure for thread condition variables

Definition at line 463 of file switch_apr.h.

Function Documentation

◆ switch_thread_cond_broadcast()

switch_status_t switch_thread_cond_broadcast ( switch_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.

Definition at line 399 of file switch_apr.c.

Referenced by switch_core_session_wake_video_thread(), and SWITCH_MODULE_RUNTIME_FUNCTION().

400 {
401  return fspr_thread_cond_broadcast(cond);
402 }

◆ switch_thread_cond_create()

switch_status_t switch_thread_cond_create ( switch_thread_cond_t **  cond,
switch_memory_pool_t pool 
)

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 mutex.

Definition at line 373 of file switch_apr.c.

Referenced by record_callback(), speech_thread(), switch_core_session_init(), switch_core_session_request_uuid(), switch_core_session_start_audio_write_thread(), switch_core_session_start_text_thread(), switch_core_session_start_video_thread(), SWITCH_MODULE_RUNTIME_FUNCTION(), switch_sql_queue_manager_init_name(), switch_system_thread(), and timer_init().

374 {
375  return fspr_thread_cond_create(cond, pool);
376 }
switch_memory_pool_t * pool

◆ switch_thread_cond_destroy()

switch_status_t switch_thread_cond_destroy ( switch_thread_cond_t cond)

Destroy the condition variable and free the associated memory.

Parameters
condthe condition variable to destroy.

Definition at line 404 of file switch_apr.c.

405 {
406  return fspr_thread_cond_destroy(cond);
407 }

◆ switch_thread_cond_signal()

switch_status_t switch_thread_cond_signal ( switch_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.

Definition at line 394 of file switch_apr.c.

Referenced by check_queue(), qm_wake(), record_callback(), speech_callback(), switch_core_session_thread_pool_worker(), switch_core_session_wake_session_thread(), and system_thread().

395 {
396  return fspr_thread_cond_signal(cond);
397 }

◆ switch_thread_cond_timedwait()

switch_status_t switch_thread_cond_timedwait ( switch_thread_cond_t cond,
switch_mutex_t mutex,
switch_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.

Definition at line 383 of file switch_apr.c.

References SWITCH_STATUS_TIMEOUT.

Referenced by switch_core_session_uninit().

384 {
385  fspr_status_t st = fspr_thread_cond_timedwait(cond, mutex, timeout);
386 
387  if (st == APR_TIMEUP) {
389  }
390 
391  return st;
392 }
switch_mutex_t * mutex

◆ switch_thread_cond_wait()

switch_status_t switch_thread_cond_wait ( switch_thread_cond_t cond,
switch_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.

Definition at line 378 of file switch_apr.c.

Referenced by recording_thread(), speech_thread(), switch_cond_next(), switch_cond_yield(), switch_core_session_run(), switch_system_thread(), switch_user_sql_thread(), timer_next(), and video_helper_thread().

379 {
380  return fspr_thread_cond_wait(cond, mutex);
381 }
switch_mutex_t * mutex