VLC 4.0.0-dev

The condition variable is the most common and generic mean for threads to wait for events triggered by other threads. More...

Collaboration diagram for Condition variables:

Data Structures

struct  vlc_cond_t
 Condition variable. More...
 

Macros

#define VLC_STATIC_COND   { NULL, VLC_STATIC_MUTEX }
 Static initializer for (static) condition variable. More...
 

Functions

void vlc_cond_init (vlc_cond_t *)
 Initializes a condition variable. More...
 
void vlc_cond_signal (vlc_cond_t *)
 Wakes up one thread waiting on a condition variable. More...
 
void vlc_cond_broadcast (vlc_cond_t *)
 Wakes up all threads waiting on a condition variable. More...
 
void vlc_cond_wait (vlc_cond_t *cond, vlc_mutex_t *mutex)
 Waits on a condition variable. More...
 
int vlc_cond_timedwait (vlc_cond_t *cond, vlc_mutex_t *mutex, vlc_tick_t deadline)
 Waits on a condition variable up to a certain date. More...
 
int vlc_cond_timedwait_daytime (vlc_cond_t *, vlc_mutex_t *, time_t)
 

Detailed Description

The condition variable is the most common and generic mean for threads to wait for events triggered by other threads.

See also POSIX pthread_cond_t .

Macro Definition Documentation

◆ VLC_STATIC_COND

#define VLC_STATIC_COND   { NULL, VLC_STATIC_MUTEX }

Static initializer for (static) condition variable.

Function Documentation

◆ vlc_cond_broadcast()

◆ vlc_cond_init()

◆ vlc_cond_signal()

void vlc_cond_signal ( vlc_cond_t cond)

Wakes up one thread waiting on a condition variable.

If any thread is currently waiting on the condition variable, at least one of those threads will be woken up. Otherwise, this function has no effects.

Note
This function is not a cancellation point.

References vlc_cond_t::head, vlc_cond_t::lock, vlc_cond_waiter::next, vlc_cond_waiter::pprev, vlc_cond_signal_waiter(), vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by addons_manager_Gather(), DecoderThread(), DecoderWaitUnblock(), dialog_id_post(), dialog_wait_interrupted(), finder_thread_interrupted(), input_ControlPush(), input_Stop(), InstallEntry(), installer_thread_interrupted(), Interrupt(), on_thumbnailer_input_event(), picture_pool_ReleaseClone(), player_on_state_changed(), QueuePush(), sout_AnnounceRegisterSDP(), sout_AnnounceUnRegister(), spu_Destroy(), spu_PrerenderEnqueue(), spu_PrerenderThread(), spu_PrerenderWake(), ThreadRun(), TsChangePause(), TsPushCmd(), TsStop(), vlc_executor_Cancel(), vlc_h2_output_destroy(), vlc_h2_output_queue(), vlc_h2_stream_data(), vlc_h2_stream_headers(), vlc_h2_stream_wake_up(), vlc_input_decoder_Delete(), vlc_input_decoder_StartWait(), vlc_input_decoder_StopWait(), vlc_mwait_i11e_wake(), vlc_player_CancelWaitError(), vlc_player_Delete(), vlc_player_destructor_AddInput(), vlc_player_destructor_AddStoppingInput(), vlc_queue_Signal(), vlc_timer_destroy(), vlc_timer_schedule(), vlm_Delete(), vout_control_Hold(), vout_control_ReleaseAndWake(), vout_control_ReleaseUnlocked(), vout_control_Wait(), and vout_control_Wake().

◆ vlc_cond_timedwait()

int vlc_cond_timedwait ( vlc_cond_t cond,
vlc_mutex_t mutex,
vlc_tick_t  deadline 
)

Waits on a condition variable up to a certain date.

This works like vlc_cond_wait() but with an additional time-out. The time-out is expressed as an absolute timestamp using the same arbitrary time reference as the vlc_tick_now() and vlc_tick_wait() functions.

Parameters
condcondition variable to wait on
mutexmutex which is unlocked while waiting, then locked again when waking up
deadlineabsolute timeout
Returns
0 if the condition was signaled, an error code in case of timeout.

References vlc_mutex_t::recursion, vlc_cond_waiter::value, vlc_atomic_timedwait(), vlc_cond_wait_finish(), and vlc_cond_wait_prepare().

Referenced by ControlPop(), RunnableRun(), RunThread(), vlc_clock_Wait(), vlc_mwait_i11e(), vlc_player_WaitRetryDelay(), vlc_timer_thread(), vout_control_Wait(), and vout_snapshot_Get().

◆ vlc_cond_timedwait_daytime()

int vlc_cond_timedwait_daytime ( vlc_cond_t cond,
vlc_mutex_t mutex,
time_t  deadline 
)

◆ vlc_cond_wait()

void vlc_cond_wait ( vlc_cond_t cond,
vlc_mutex_t mutex 
)

Waits on a condition variable.

The calling thread will be suspended until another thread calls vlc_cond_signal() or vlc_cond_broadcast() on the same condition variable, the thread is cancelled with vlc_cancel(), or the system causes a spurious unsolicited wake-up.

A mutex is needed to wait on a condition variable. It must not be a recursive mutex. Although it is possible to use the same mutex for multiple condition, it is not valid to use different mutexes for the same condition variable at the same time from different threads.

The canonical way to use a condition variable to wait for event foobar is:

while (!foobar)
vlc_cond_wait(&wait, &lock);
// -- foobar is now true, do something about it here --
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition: threads.c:291
void vlc_mutex_unlock(vlc_mutex_t *mtx)
Releases a mutex.
Definition: threads.c:160
void vlc_mutex_lock(vlc_mutex_t *mtx)
Acquires a mutex.
Definition: threads.c:106
vlc_mutex_t lock
Definition: rand.c:33
Parameters
condcondition variable to wait on
mutexmutex which is unlocked while waiting, then locked again when waking up.

References vlc_mutex_t::recursion, vlc_cond_waiter::value, vlc_atomic_wait(), vlc_cond_wait_finish(), and vlc_cond_wait_prepare().

Referenced by ControlPop(), dialog_wait(), FinderThread(), InstallerThread(), Manage(), picture_pool_Wait(), QueueTake(), RunnableRun(), spu_PrerenderCancel(), spu_PrerenderPause(), spu_PrerenderSync(), spu_PrerenderThread(), TsRun(), vlc_executor_WaitIdle(), vlc_fifo_WaitCond(), vlc_h2_output_dequeue(), vlc_h2_stream_read(), vlc_h2_stream_wait(), vlc_h2_stream_write(), vlc_player_CondWait(), vlc_player_destructor_Thread(), vlc_queue_Wait(), vlc_timer_thread(), vout_control_Hold(), vout_control_Wait(), and WaitUnused().