VLC  4.0.0-dev
Data Structures | Macros | Functions

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()

void vlc_cond_broadcast ( vlc_cond_t )

◆ vlc_cond_init()

void vlc_cond_init ( vlc_cond_t )

◆ vlc_cond_signal()

void vlc_cond_signal ( vlc_cond_t )

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(), background_worker_RequestProbe(), BackgroundWorkerCancelLocked(), DecoderThread(), DecoderUpdatePreroll(), dialog_id_post(), dialog_wait_interrupted(), finder_thread_interrupted(), input_ControlPush(), input_Stop(), InstallEntry(), installer_thread_interrupted(), ModuleThread_PlayAudio(), ModuleThread_PlaySpu(), ModuleThread_PlayVideo(), picture_pool_ReleasePicture(), player_on_state_changed(), QueuePush(), RemoveThread(), sout_AnnounceRegisterSDP(), sout_AnnounceUnRegister(), spu_Destroy(), spu_PrerenderEnqueue(), spu_PrerenderThread(), spu_PrerenderWake(), TsChangePause(), TsPushCmd(), TsStop(), vlc_cond_timedwait_daytime(), 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_Pop(), vout_control_Push(), vout_control_Release(), 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_cond_waiter::value, vlc_atomic_timedwait(), vlc_cond_wait_finish(), and vlc_cond_wait_prepare().

Referenced by ControlPop(), QueueTake(), RunThread(), Thread(), vlc_clock_Wait(), vlc_mwait_i11e(), vlc_player_WaitRetryDelay(), vlc_timer_thread(), vout_control_Pop(), and vout_snapshot_Get().

◆ vlc_cond_timedwait_daytime()

int vlc_cond_timedwait_daytime ( vlc_cond_t ,
vlc_mutex_t ,
time_t   
)

◆ 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 --
Parameters
condcondition variable to wait on
mutexmutex which is unlocked while waiting, then locked again when waking up.

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

Referenced by background_worker_Delete(), ControlPop(), DecoderWaitUnblock(), dialog_wait(), FinderThread(), InstallerThread(), Manage(), picture_pool_Wait(), spu_PrerenderCancel(), spu_PrerenderPause(), spu_PrerenderSync(), spu_PrerenderThread(), TsRun(), vlc_cond_timedwait_daytime(), vlc_fifo_WaitCond(), vlc_h2_output_dequeue(), vlc_h2_stream_read(), vlc_h2_stream_wait(), vlc_input_decoder_Wait(), vlc_player_CondWait(), vlc_player_destructor_Thread(), vlc_queue_Wait(), vlc_timer_thread(), vout_control_Hold(), vout_control_Pop(), and WaitUnused().