VLC
4.0.0-dev
|
![]() |
Modules | |
Interruptible sleep | |
Mutual exclusion locks | |
Condition variables | |
The condition variable is the most common and generic mean for threads to wait for events triggered by other threads. | |
Semaphores | |
The semaphore is the simplest thread synchronization primitive, consisting of a simple counter. | |
Read/write locks | |
Read/write locks are a type of thread synchronization primitive meant to protect access to data that is mostly read, and rarely written. | |
Thread-specific variables | |
Asynchronous/threaded timers | |
Files | |
file | vlc_threads.h |
Thread primitive declarations. | |
Data Structures | |
struct | vlc_thread_t |
Thread handle. More... | |
struct | vlc_once_t |
One-time initialization. More... | |
Macros | |
#define | LIBVLC_USE_PTHREAD 1 |
Whether LibVLC threads are based on POSIX threads. More... | |
#define | LIBVLC_USE_PTHREAD_CLEANUP 1 |
Whether LibVLC thread cancellation is based on POSIX threads. More... | |
#define | VLC_THREAD_CANCELED PTHREAD_CANCELED |
Return value of a canceled thread. More... | |
#define | VLC_THREAD_PRIORITY_LOW 0 |
#define | VLC_THREAD_PRIORITY_INPUT 10 |
#define | VLC_THREAD_PRIORITY_AUDIO 5 |
#define | VLC_THREAD_PRIORITY_VIDEO 0 |
#define | VLC_THREAD_PRIORITY_OUTPUT 15 |
#define | VLC_THREAD_PRIORITY_HIGHEST 20 |
#define | VLC_STATIC_ONCE { ATOMIC_VAR_INIT(0) } |
Static initializer for one-time initialization. More... | |
#define | vlc_once(once, cb) vlc_once_inline(once, cb) |
#define | VLC_HARD_MIN_SLEEP VLC_TICK_FROM_MS(10) /* 10 milliseconds = 1 tick at 100Hz */ |
#define | VLC_SOFT_MIN_SLEEP VLC_TICK_FROM_SEC(9) /* 9 seconds */ |
#define | check_delay(d) (d) |
#define | check_deadline(d) (d) |
#define | vlc_tick_sleep(d) vlc_tick_sleep(check_delay(d)) |
#define | vlc_tick_wait(d) vlc_tick_wait(check_deadline(d)) |
#define | vlc_cleanup_push(routine, arg) pthread_cleanup_push (routine, arg) |
Registers a thread cancellation handler. More... | |
#define | vlc_cleanup_pop() pthread_cleanup_pop (0) |
Unregisters the last cancellation handler. More... | |
#define | mutex_cleanup_push(lock) vlc_cleanup_push (vlc_cleanup_lock, lock) |
#define | vlc_global_lock(n) vlc_global_mutex(n, true) |
Acquires a global mutex. More... | |
#define | vlc_global_unlock(n) vlc_global_mutex(n, false) |
Releases a global mutex. More... | |
Typedefs | |
typedef struct vlc_cleanup_t | vlc_cleanup_t |
Enumerations | |
enum | { VLC_AVCODEC_MUTEX = 0, VLC_GCRYPT_MUTEX, VLC_XLIB_MUTEX, VLC_MOSAIC_MUTEX, VLC_MAX_MUTEX } |
Functions | |
void | vlc_testcancel (void) |
Issues an explicit deferred cancellation point. More... | |
void | vlc_once_inline (vlc_once_t *restrict once, void(*cb)(void)) |
Executes a function one time. More... | |
void | vlc_atomic_wait (void *addr, unsigned val) |
Waits on an address. More... | |
int | vlc_atomic_timedwait (void *addr, unsigned val, vlc_tick_t deadline) |
Waits on an address with a time-out. More... | |
int | vlc_atomic_timedwait_daytime (void *addr, unsigned val, time_t deadline) |
void | vlc_atomic_notify_one (void *addr) |
Wakes up one thread on an address. More... | |
void | vlc_atomic_notify_all (void *addr) |
Wakes up all thread on an address. More... | |
int | vlc_clone (vlc_thread_t *th, void *(*entry)(void *), void *data, int priority) |
Creates and starts a new thread. More... | |
void | vlc_cancel (vlc_thread_t) |
Marks a thread as cancelled. More... | |
void | vlc_join (vlc_thread_t th, void **result) |
Waits for a thread to complete (if needed), then destroys it. More... | |
int | vlc_savecancel (void) |
Disables thread cancellation. More... | |
void | vlc_restorecancel (int state) |
Restores the cancellation state. More... | |
void | vlc_control_cancel (vlc_cleanup_t *) |
Internal handler for thread cancellation. More... | |
unsigned long | vlc_thread_id (void) |
Thread identifier. More... | |
vlc_tick_t | vlc_tick_now (void) |
Precision monotonic clock. More... | |
void | vlc_tick_wait (vlc_tick_t deadline) |
Waits until a deadline. More... | |
void | vlc_tick_sleep (vlc_tick_t delay) |
Waits for an interval of time. More... | |
unsigned | vlc_GetCPUCount (void) |
Count CPUs. More... | |
static void | vlc_cleanup_lock (void *lock) |
void | vlc_cancel_addr_set (atomic_uint *addr) |
void | vlc_cancel_addr_clear (atomic_uint *addr) |
void | vlc_global_mutex (unsigned, bool) |
Internal handler for global mutexes. More... | |
#define check_deadline | ( | d | ) | (d) |
#define check_delay | ( | d | ) | (d) |
#define LIBVLC_USE_PTHREAD 1 |
Whether LibVLC threads are based on POSIX threads.
#define LIBVLC_USE_PTHREAD_CLEANUP 1 |
Whether LibVLC thread cancellation is based on POSIX threads.
#define mutex_cleanup_push | ( | lock | ) | vlc_cleanup_push (vlc_cleanup_lock, lock) |
Referenced by httpdLoop(), TsRun(), vlc_cond_timedwait_daytime(), vlc_h2_stream_read(), vlc_h2_stream_wait(), vout_control_Pop(), and WaitUnused().
#define vlc_cleanup_pop | ( | ) | pthread_cleanup_pop (0) |
Unregisters the last cancellation handler.
This pops the cancellation handler that was last pushed with vlc_cleanup_push() in the calling thread.
Referenced by block_FifoGet(), block_File(), detached_thread(), httpdLoop(), spu_PrerenderThread(), TsRun(), vlc_accept_i11e(), vlc_cond_timedwait(), vlc_cond_timedwait_daytime(), vlc_cond_wait(), vlc_global_mutex(), vlc_h2_frame_recv(), vlc_h2_frame_send(), vlc_h2_recv_thread(), vlc_h2_stream_read(), vlc_h2_stream_wait(), vlc_mwait_i11e(), vlc_poll_i11e(), vlc_poll_i11e_inner(), vlc_sem_wait_i11e(), vlc_tls_ClientSessionCreate(), vout_control_Pop(), and WaitUnused().
Registers a thread cancellation handler.
This pushes a function to run if the thread is cancelled (or otherwise exits prematurely).
If multiple procedures are registered, they are handled in last-in first-out order.
routine | procedure to call if the thread ends |
arg | argument for the procedure |
Referenced by detached_thread(), spu_PrerenderThread(), TsRun(), vlc_accept_i11e(), vlc_cond_timedwait(), vlc_cond_timedwait_daytime(), vlc_cond_wait(), vlc_global_mutex(), vlc_h2_frame_recv(), vlc_h2_frame_send(), vlc_h2_recv_thread(), vlc_mwait_i11e(), vlc_poll_i11e(), vlc_poll_i11e_inner(), vlc_sem_wait_i11e(), and vlc_tls_ClientSessionCreate().
#define vlc_global_lock | ( | n | ) | vlc_global_mutex(n, true) |
Acquires a global mutex.
Referenced by vlc_avcodec_lock(), vlc_gcrypt_init(), vlc_mta_acquire(), vlc_mta_release(), and vlc_xlib_init().
#define vlc_global_unlock | ( | n | ) | vlc_global_mutex(n, false) |
Releases a global mutex.
Referenced by vlc_avcodec_unlock(), vlc_gcrypt_init(), vlc_mta_acquire(), vlc_mta_release(), and vlc_xlib_init().
#define VLC_HARD_MIN_SLEEP VLC_TICK_FROM_MS(10) /* 10 milliseconds = 1 tick at 100Hz */ |
#define vlc_once | ( | once, | |
cb | |||
) | vlc_once_inline(once, cb) |
Referenced by vlc_once_inline().
#define VLC_SOFT_MIN_SLEEP VLC_TICK_FROM_SEC(9) /* 9 seconds */ |
#define VLC_STATIC_ONCE { ATOMIC_VAR_INIT(0) } |
Static initializer for one-time initialization.
#define VLC_THREAD_CANCELED PTHREAD_CANCELED |
Return value of a canceled thread.
#define VLC_THREAD_PRIORITY_AUDIO 5 |
Referenced by decoder_New().
#define VLC_THREAD_PRIORITY_HIGHEST 20 |
#define VLC_THREAD_PRIORITY_INPUT 10 |
Referenced by input_Start(), TsStart(), vlc_demux_chained_New(), vlc_h2_conn_create(), vlc_h2_output_create(), and vlc_timer_create().
#define VLC_THREAD_PRIORITY_LOW 0 |
#define VLC_THREAD_PRIORITY_OUTPUT 15 |
Referenced by vout_Request().
#define VLC_THREAD_PRIORITY_VIDEO 0 |
Referenced by decoder_New(), and spu_Create().
#define vlc_tick_sleep | ( | d | ) | vlc_tick_sleep(check_delay(d)) |
Referenced by aout_Drain(), EsOutDrainDecoder(), and ModuleThread_NewSpuBuffer().
#define vlc_tick_wait | ( | d | ) | vlc_tick_wait(check_deadline(d)) |
Referenced by TsRun(), and vlc_mwait_i11e().
typedef struct vlc_cleanup_t vlc_cleanup_t |
anonymous enum |
void vlc_atomic_notify_all | ( | void * | addr | ) |
Wakes up all thread on an address.
Wakes up all threads sleeping on the specified address (if any). Any thread sleeping within a call to vlc_atomic_wait() or vlc_atomic_timedwait() with the specified address as first call parameter will be woken up.
addr | address identifying which threads to wake up |
References ARRAY_SIZE, wait_bucket::lock, vlc_clock_id, vlc_futex_wake(), vlc_umtx_wake(), wait_bucket::wait, wait_bucket_get(), wait_buckets, and wait_bucket::waiters.
Referenced by vlc_atomic_notify_one(), vlc_cancel(), and vlc_once().
void vlc_atomic_notify_one | ( | void * | addr | ) |
Wakes up one thread on an address.
Wakes up (at least) one of the thread sleeping on the specified address. The address must be equal to the first parameter given by at least one thread sleeping within the vlc_atomic_wait() or vlc_atomic_timedwait() functions. If no threads are found, this function does nothing.
addr | address identifying which threads may be woken up |
References vlc_atomic_notify_all(), vlc_futex_wake(), and vlc_umtx_wake().
Referenced by vlc_cond_signal_waiter(), vlc_mutex_unlock(), and vlc_sem_post().
int vlc_atomic_timedwait | ( | void * | addr, |
unsigned | val, | ||
vlc_tick_t | deadline | ||
) |
Waits on an address with a time-out.
This function operates as vlc_atomic_wait() but provides an additional time-out. If the deadline is reached, the thread resumes and the function returns.
addr | address to check for |
val | value to match at the address |
deadline | deadline to wait until |
0 | the function was woken up before the time-out |
ETIMEDOUT | the deadline was reached |
References MS_FROM_VLC_TICK, timespec_from_vlc_tick(), vlc_assert_unreachable, vlc_atomic_timedwait_timespec(), vlc_futex_wait(), VLC_TICK_FROM_MS, vlc_tick_now(), vlc_timespec_adjust(), and vlc_umtx_wait().
Referenced by vlc_cond_timedwait(), and vlc_sem_timedwait().
int vlc_atomic_timedwait_daytime | ( | void * | addr, |
unsigned | val, | ||
time_t | deadline | ||
) |
References timespec::tv_sec, vlc_assert_unreachable, vlc_atomic_timedwait_timespec(), vlc_futex_wait(), and vlc_timespec_adjust().
Referenced by vlc_cond_timedwait_daytime().
void vlc_atomic_wait | ( | void * | addr, |
unsigned | val | ||
) |
Waits on an address.
Puts the calling thread to sleep if a specific unsigned 32-bits value is stored at a specified address. The thread will sleep until it is woken up by a call to vlc_atomic_notify_one() or vlc_atomic_notify_all() in another thread, or spuriously.
If the value does not match, do nothing and return immediately.
addr | address to check for |
val | value to match at the address |
References wait_bucket::lock, vlc_futex_wait(), vlc_umtx_wait(), wait_bucket::wait, wait_bucket_enter(), and wait_bucket_leave().
Referenced by vlc_cond_wait(), vlc_mutex_lock(), vlc_once(), and vlc_sem_wait().
void vlc_cancel | ( | vlc_thread_t | ) |
Marks a thread as cancelled.
Next time the target thread reaches a cancellation point (while not having disabled cancellation), it will run its cancellation cleanup handler, the thread variable destructors, and terminate.
vlc_join() must be used regardless of a thread being cancelled or not, to avoid leaking resources.
References vlc_thread::addr, vlc_thread_t::handle, vlc_atomic_notify_all(), vlc_cancel_self(), vlc_mutex_lock(), and vlc_mutex_unlock().
Referenced by httpd_HostDelete(), spu_Destroy(), TsStop(), vlc_getaddrinfo_i11e(), vlc_h2_conn_destroy(), vlc_h2_output_destroy(), and vout_StopDisplay().
void vlc_cancel_addr_clear | ( | atomic_uint * | addr | ) |
References vlc_thread::addr, vlc_thread::lock, vlc_thread::thread, thread_key, vlc_mutex_lock(), vlc_mutex_unlock(), and vlc_thread::wait.
Referenced by vlc_global_mutex().
void vlc_cancel_addr_set | ( | atomic_uint * | addr | ) |
References vlc_thread::addr, vlc_thread::lock, vlc_thread::thread, thread_key, vlc_mutex_lock(), vlc_mutex_unlock(), and vlc_thread::wait.
Referenced by vlc_global_mutex().
|
inlinestatic |
References vlc_mutex_unlock().
int vlc_clone | ( | vlc_thread_t * | th, |
void *(*)(void *) | entry, | ||
void * | data, | ||
int | priority | ||
) |
Creates and starts a new thread.
The thread must be joined with vlc_join() to reclaim resources when it is not needed anymore.
th | storage space for the handle of the new thread (cannot be NULL) [OUT] |
entry | entry point for the thread |
data | data parameter given to the entry point |
priority | thread priority value |
References vlc_clone_attr().
Referenced by addons_manager_Gather(), decoder_New(), httpd_HostCreate(), input_Start(), InstallEntry(), sout_AnnounceRegisterSDP(), spu_Create(), StartWorker(), TsStart(), update_Check(), update_Download(), vlc_demux_chained_New(), vlc_getaddrinfo_i11e(), vlc_h2_conn_create(), vlc_h2_output_create(), vlc_mta_acquire(), vlc_player_New(), vlc_timer_create(), vlm_New(), and vout_Request().
void vlc_control_cancel | ( | vlc_cleanup_t * | ) |
Internal handler for thread cancellation.
Do not call this function directly. Use wrapper macros instead: vlc_cleanup_push(), vlc_cleanup_pop().
References vlc_thread::cleaners, thread_key, vlc_assert_unreachable, and vlc_threadvar_get().
unsigned vlc_GetCPUCount | ( | void | ) |
Count CPUs.
References count, unlikely, and vlc_alloc().
Referenced by vlc_timer_schedule_asap().
void vlc_global_mutex | ( | unsigned | , |
bool | |||
) |
Internal handler for global mutexes.
Do not use this function directly. Use helper macros instead: vlc_global_lock(), vlc_global_unlock().
References ARRAY_SIZE, lock, static_assert, vlc_cancel_addr_clear(), vlc_cancel_addr_finish, vlc_cancel_addr_prepare, vlc_cancel_addr_set(), vlc_cleanup_pop, vlc_cleanup_push, VLC_MAX_MUTEX, vlc_mutex_lock(), vlc_mutex_unlock(), VLC_STATIC_MUTEX, and vlc_testcancel().
void vlc_join | ( | vlc_thread_t | th, |
void ** | result | ||
) |
Waits for a thread to complete (if needed), then destroys it.
th | thread handle |
result | [OUT] pointer to write the thread return value or NULL |
References clean_detached_thread(), vlc_thread_t::handle, vlc_testcancel(), VLC_THREAD_ASSERT, vlc_thread_destroy(), and vlc_WaitForSingleObject().
Referenced by addons_manager_Delete(), CloseWorker(), httpd_HostDelete(), input_Close(), sout_AnnounceUnRegister(), spu_Destroy(), TsStop(), update_Check(), update_Delete(), update_Download(), vlc_demux_chained_Delete(), vlc_getaddrinfo_i11e(), vlc_h2_conn_destroy(), vlc_h2_output_destroy(), vlc_input_decoder_Delete(), vlc_mta_release(), vlc_player_Delete(), vlc_timer_destroy(), vlm_Delete(), and vout_StopDisplay().
|
inline |
Executes a function one time.
The first time this function is called with a given one-time initialization object, it executes the provided callback. Any further call with the same object will be a no-op.
In the corner case that the first time execution is ongoing in another thread, then the function will wait for completion on the other thread (and then synchronize memory) before it returns. This ensures that, no matter what, the callback has been executed exactly once and its side effects are visible after the function returns.
once | a one-time initialization object |
cb | callback to execute (the first time) |
void vlc_restorecancel | ( | int | state | ) |
Restores the cancellation state.
This function restores the cancellation state of the calling thread to a state previously saved by vlc_savecancel().
state | previous state as returned by vlc_savecancel(). |
References vlc_thread::killable, state, thread_key, unlikely, VLC_THREAD_ASSERT, vlc_thread_fatal(), and vlc_threadvar_get().
Referenced by FinderThread(), httpdLoop(), InstallerThread(), spu_PrerenderThread(), Thread(), TsRun(), update_CheckReal(), update_DownloadReal(), vlc_h2_output_dequeue(), vlc_h2_recv_thread(), vlc_https_connect_proxy(), vlc_https_recv(), vlc_https_send(), vlc_mutex_lock(), vlc_object_deinit(), vlc_poll_i11e_inner(), vlc_poll_i11e_wake(), vlc_thread_fatal(), vlc_tls_ClientSessionCreate(), vlc_tls_ServerSessionCreate(), vlc_tls_SessionDelete(), and vlc_vaLogCallback().
int vlc_savecancel | ( | void | ) |
Disables thread cancellation.
This functions saves the current cancellation state (enabled or disabled), then disables cancellation for the calling thread. It must be called before entering a piece of code that is not cancellation-safe, unless it can be proven that the calling thread will not be cancelled.
References vlc_thread::killable, state, thread_key, VLC_THREAD_ASSERT, and vlc_threadvar_get().
Referenced by FinderThread(), httpdLoop(), InstallerThread(), spu_PrerenderThread(), Thread(), TsRun(), update_CheckReal(), update_DownloadReal(), vlc_h2_output_dequeue(), vlc_h2_recv_thread(), vlc_https_connect_proxy(), vlc_https_recv(), vlc_https_send(), vlc_mutex_lock(), vlc_object_deinit(), vlc_poll_i11e_inner(), vlc_poll_i11e_wake(), vlc_thread_fatal(), vlc_tls_ClientSessionCreate(), vlc_tls_ServerSessionCreate(), vlc_tls_SessionDelete(), and vlc_vaLogCallback().
void vlc_testcancel | ( | void | ) |
Issues an explicit deferred cancellation point.
This has no effects if thread cancellation is disabled. This can be called when there is a rather slow non-sleeping operation. This is also used to force a cancellation point in a function that would otherwise not always be one (block_FifoGet() is an example).
References vlc_thread::cancel_event, vlc_thread::cleaners, vlc_thread::data, vlc_thread::done_event, vlc_thread::id, vlc_thread::killable, vlc_thread::killed, p, thread_key, vlc_cancel_self(), vlc_thread_cleanup(), vlc_thread_destroy(), and vlc_threadvar_get().
Referenced by block_FifoGet(), net_Read(), net_Write(), vlc_global_mutex(), vlc_join(), vlc_poll_i11e_inner(), vlc_select(), vlc_tick_now(), and vlc_tick_wait().
unsigned long vlc_thread_id | ( | void | ) |
Thread identifier.
This function returns the identifier of the calling thread. The identifier cannot change for the entire duration of the thread, and no other thread can have the same identifier at the same time in the same process. Typically, the identifier is also unique across all running threads of all existing processes, but that depends on the operating system.
There are no particular semantics to the thread ID with LibVLC. It is provided mainly for tracing and debugging.
References unlikely.
Referenced by vlc_thread_fatal(), vlc_thread_fatal_print(), and vlc_vaLog().
vlc_tick_t vlc_tick_now | ( | void | ) |
Precision monotonic clock.
In principles, the clock has a precision of 1 MHz. But the actual resolution may be much lower, especially when it comes to sleeping with vlc_tick_wait() or vlc_tick_sleep(). Most general-purpose operating systems provide a resolution of only 100 to 1000 Hz.
References freq, lldiv(), mdate_selected, Q2LL, lldiv_t::quot, lldiv_t::rem, unlikely, vlc_clock_conversion, vlc_clock_setup, vlc_testcancel(), VLC_TICK_FROM_NS, vlc_tick_from_samples(), vlc_tick_from_sec, vlc_tick_from_timespec, vlc_tick_now(), vlc_tick_sleep(), and vlc_tick_wait().
Referenced by aout_DecDrain(), aout_DecPlay(), aout_DecSilence(), CmdInitAdd(), CmdInitControl(), CmdInitDel(), CmdInitPrivControl(), CmdInitSend(), Control(), EsOutDecodersStopBuffering(), EsOutGetBuffering(), EsOutVaControlLocked(), httpdLoop(), ImageRead(), Init(), input_clock_ConvertTS(), input_rate_Add(), input_thread_Events(), MainLoop(), net_Connect(), OSDWidget(), QueueTake(), RunThread(), sout_AnnounceRegisterSDP(), spu_PrerenderText(), spu_PutSubpicture(), Thread(), ThreadDisplayPicture(), ThreadDisplayPreparePicture(), ThreadDisplayRenderPicture(), TsStart(), vlc_atomic_timedwait(), vlc_demux_chained_Thread(), vlc_input_decoder_AddVoutOverlay(), vlc_msleep_i11e(), vlc_player_input_GetPos(), vlc_player_input_GetTime(), vlc_player_WaitRetryDelay(), vlc_tick_now(), vlc_tick_sleep(), vlc_tick_wait(), vlc_timer_schedule(), vlc_timer_thread(), vlc_tls_ClientSessionCreate(), vout_chrono_Start(), vout_chrono_Stop(), vout_display_window_MouseEvent(), vout_OSDEpg(), vout_OSDText(), vout_SetInterlacingState(), vout_snapshot_Get(), and VoutSnapshotPip().
void vlc_tick_sleep | ( | vlc_tick_t | delay | ) |
Waits for an interval of time.
delay | how long to wait (in microseconds) |
References timespec_from_vlc_tick(), vlc_tick_now(), and vlc_tick_wait().
Referenced by vlc_tick_now(), and vlc_tick_wait().
void vlc_tick_wait | ( | vlc_tick_t | deadline | ) |
Waits until a deadline.
deadline | timestamp to wait for (vlc_tick_now()) |
References timespec_from_vlc_tick(), unlikely, vlc_clock_once, vlc_clock_prec, vlc_clock_setup_once(), vlc_Sleep(), vlc_testcancel(), vlc_tick_now(), and vlc_tick_sleep().
Referenced by vlc_tick_now(), and vlc_tick_sleep().