58# define ETIMEDOUT 10060
62# define VLC_THREAD_CANCELED ((void*) UINTPTR_MAX)
67#elif defined (__OS2__)
71#define VLC_THREAD_CANCELED ((void*) UINTPTR_MAX)
76# define pthread_sigmask sigprocmask
78#elif defined (__ANDROID__)
82# define LIBVLC_USE_PTHREAD_CLEANUP 1
85#define VLC_THREAD_CANCELED ((void*) UINTPTR_MAX)
96# define LIBVLC_USE_PTHREAD 1
101# define LIBVLC_USE_PTHREAD_CLEANUP 1
114#define VLC_THREAD_CANCELED PTHREAD_CANCELED
147 atomic_uint recursion;
153 unsigned int recursion;
165#define VLC_STATIC_MUTEX { \
247#define vlc_mutex_assert(m) assert(vlc_mutex_held(m))
277#define VLC_STATIC_COND { NULL, VLC_STATIC_MUTEX }
530#define VLC_STATIC_ONCE { 0 }
560 if (
unlikely(atomic_load_explicit(&once->value, memory_order_acquire) < 3))
564#define vlc_once_begin(once) vlc_once_begin_inline(once)
669VLC_WARN_CALL(
"thread name too big")
670const
char * vlc_thread_name_too_big( const
char * thread_name )
675# define check_name_length( thread_name ) \
676 ((__builtin_constant_p(__builtin_strlen(thread_name) > 15) && \
677 __builtin_strlen(thread_name) > 15) \
678 ? vlc_thread_name_too_big(thread_name): thread_name)
690#if defined(check_name_length)
691# define vlc_thread_set_name(name) vlc_thread_set_name(check_name_length(name))
815#define VLC_HARD_MIN_SLEEP VLC_TICK_FROM_MS(10)
816#define VLC_SOFT_MIN_SLEEP VLC_TICK_FROM_SEC(9)
827VLC_ERROR_CALL(
"sorry, cannot sleep for such short a time")
836VLC_WARN_CALL(
"use proper event handling instead of short delay")
842# define check_delay( d ) \
843 ((__builtin_constant_p(d < VLC_HARD_MIN_SLEEP) \
844 && (d < VLC_HARD_MIN_SLEEP)) \
845 ? impossible_delay(d) \
846 : ((__builtin_constant_p(d < VLC_SOFT_MIN_SLEEP) \
847 && (d < VLC_SOFT_MIN_SLEEP)) \
853VLC_ERROR_CALL(
"deadlines can not be constant")
859# define check_deadline( d ) \
860 (__builtin_constant_p(d) ? impossible_deadline(d) : d)
863#if defined(check_delay)
864#define vlc_tick_sleep(d) vlc_tick_sleep(check_delay(d))
866#if defined(check_deadline)
867#define vlc_tick_wait(d) vlc_tick_wait(check_deadline(d))
902#define VLC_TIMER_DISARM (0)
903#define VLC_TIMER_FIRE_ONCE (0)
957#if defined (LIBVLC_USE_PTHREAD_CLEANUP)
975# define vlc_cleanup_push( routine, arg ) pthread_cleanup_push (routine, arg)
983# define vlc_cleanup_pop( ) pthread_cleanup_pop (0)
989 void (*proc) (
void *);
998# define vlc_cleanup_push( routine, arg ) \
1000 vlc_control_cancel(&(vlc_cleanup_t){ NULL, routine, arg })
1002# define vlc_cleanup_pop( ) \
1003 vlc_control_cancel (NULL); \
1006# define vlc_cleanup_push(routine, arg) \
1007 static_assert(false, "don't use vlc_cleanup_push in portable C++ code")
1008# define vlc_cleanup_pop() \
1009 static_assert(false, "don't use vlc_cleanup_pop in portable C++ code")
1021class vlc_mutex_locker
1031 ~vlc_mutex_locker (
void)
1063#define vlc_global_lock( n ) vlc_global_mutex(n, true)
1068#define vlc_global_unlock( n ) vlc_global_mutex(n, false)
size_t count
Definition core.c:403
#define VLC_USED
Definition fourcc_gen.c:32
#define VLC_API
Definition fourcc_gen.c:31
#define unlikely(p)
Predicted false condition.
Definition vlc_common.h:246
void vlc_cond_signal(vlc_cond_t *)
Wakes up one thread waiting on a condition variable.
Definition threads.c:193
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.
Definition threads.c:292
void vlc_cond_broadcast(vlc_cond_t *)
Wakes up all threads waiting on a condition variable.
Definition threads.c:220
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition threads.c:280
void vlc_cond_init(vlc_cond_t *)
Initializes a condition variable.
Definition threads.c:174
void vlc_latch_count_down(vlc_latch_t *latch, size_t n)
Decrements the value of a latch.
Definition threads.c:420
void vlc_latch_wait(vlc_latch_t *)
Waits on a latch.
Definition threads.c:437
void vlc_latch_count_down_and_wait(vlc_latch_t *latch, size_t n)
Decrements the value of a latch and waits on it.
Definition threads.c:425
bool vlc_latch_is_ready(const vlc_latch_t *latch)
Checks if a latch is ready.
Definition threads.c:431
void vlc_latch_init(vlc_latch_t *latch, size_t value)
Initializes a latch.
Definition threads.c:397
void vlc_mutex_unlock(vlc_mutex_t *)
Releases a mutex.
Definition threads.c:149
void vlc_mutex_init_recursive(vlc_mutex_t *)
Initializes a recursive mutex.
Definition threads.c:80
void vlc_mutex_init(vlc_mutex_t *)
Initializes a fast mutex.
Definition threads.c:75
void vlc_mutex_lock(vlc_mutex_t *)
Acquires a mutex.
Definition threads.c:95
bool vlc_mutex_held(const vlc_mutex_t *)
Checks if a mutex is locked.
Definition threads.c:85
int vlc_mutex_trylock(vlc_mutex_t *)
Tries to acquire a mutex.
Definition threads.c:115
int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline)
Waits on a semaphore within a deadline.
Definition threads.c:360
int vlc_sem_trywait(vlc_sem_t *sem)
Tries to decrement a semaphore.
Definition threads.c:381
void vlc_sem_wait(vlc_sem_t *)
Waits on a semaphore.
Definition threads.c:344
void vlc_sem_init(vlc_sem_t *sem, unsigned count)
Initializes a semaphore.
Definition threads.c:323
int vlc_sem_post(vlc_sem_t *)
Increments the value of a semaphore.
Definition threads.c:328
void vlc_testcancel(void)
Issues an explicit deferred cancellation point.
Definition thread.c:189
void vlc_global_mutex(unsigned, bool)
Internal handler for global mutexes.
Definition threads.c:46
static void vlc_once(vlc_once_t *restrict once, void(*cb)(void *), void *opaque)
Executes a function one time.
Definition vlc_threads.h:599
void vlc_cancel(vlc_thread_t)
Marks a thread as cancelled.
Definition thread.c:165
void vlc_once_complete(vlc_once_t *restrict once)
Completes a one-time initialization.
Definition threads.c:521
void vlc_restorecancel(int state)
Restores the cancellation state.
Definition thread.c:181
unsigned long vlc_thread_id(void)
Thread identifier.
Definition thread.c:30
void vlc_tick_sleep(vlc_tick_t delay)
Waits for an interval of time.
Definition thread.c:248
void vlc_join(vlc_thread_t th, void **result)
Waits for a thread to complete (if needed), then destroys it.
Definition thread.c:155
#define vlc_once_begin(once)
Definition vlc_threads.h:565
int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data)
Creates and starts a new thread.
Definition thread.c:150
unsigned vlc_GetCPUCount(void)
Count CPUs.
Definition thread.c:265
vlc_tick_t vlc_tick_now(void)
Precision monotonic clock.
Definition thread.c:253
void vlc_control_cancel(vlc_cleanup_t *)
Internal handler for thread cancellation.
Definition missing.c:142
#define VLC_HARD_MIN_SLEEP
Definition vlc_threads.h:816
static bool vlc_once_begin_inline(vlc_once_t *restrict once)
Definition vlc_threads.h:558
void vlc_tick_wait(vlc_tick_t deadline)
Waits until a deadline.
Definition thread.c:224
int vlc_savecancel(void)
Disables thread cancellation.
Definition thread.c:171
struct vlc_cleanup_t vlc_cleanup_t
Definition vlc_threads.h:747
void vlc_thread_set_name(const char *name)
Set the thread name of the current thread.
Definition thread.c:28
@ VLC_MAX_MUTEX
Definition vlc_threads.h:1050
@ VLC_GCRYPT_MUTEX
Definition vlc_threads.h:1043
@ VLC_AVCODEC_MUTEX
Definition vlc_threads.h:1042
@ VLC_XLIB_MUTEX
Definition vlc_threads.h:1044
@ VLC_MOSAIC_MUTEX
Definition vlc_threads.h:1045
pthread_key_t vlc_threadvar_t
Thread-local key handle.
Definition vlc_threads.h:122
void * vlc_threadvar_get(vlc_threadvar_t)
Gets the value of a thread-local variable for the calling thread.
Definition thread.c:218
void vlc_threadvar_delete(vlc_threadvar_t *)
Deallocates a thread-specific variable.
Definition thread.c:208
int vlc_threadvar_set(vlc_threadvar_t key, void *value)
Sets a thread-specific variable.
Definition thread.c:213
int vlc_threadvar_create(vlc_threadvar_t *key, void(*destr)(void *))
Allocates a thread-specific variable.
Definition thread.c:203
void vlc_timer_schedule(vlc_timer_t timer, bool absolute, vlc_tick_t value, vlc_tick_t interval)
Arms or disarms an initialized timer.
Definition thread.c:839
struct vlc_timer * vlc_timer_t
Threaded timer handle.
Definition vlc_threads.h:129
static void vlc_timer_disarm(vlc_timer_t timer)
Definition vlc_threads.h:927
#define VLC_TIMER_DISARM
Definition vlc_threads.h:903
unsigned vlc_timer_getoverrun(vlc_timer_t timer)
Fetches and resets the overrun counter for a timer.
Definition thread.c:862
int vlc_timer_create(vlc_timer_t *id, void(*func)(void *), void *data)
Initializes an asynchronous timer.
Definition thread.c:806
static void vlc_timer_schedule_asap(vlc_timer_t timer, vlc_tick_t interval)
Definition vlc_threads.h:932
void vlc_timer_destroy(vlc_timer_t timer)
Destroys an initialized timer.
Definition thread.c:826
const char name[16]
Definition httpd.c:1298
vlc_mutex_t lock
Definition rand.c:33
static thread_local struct @85 state
Definition fourcc_gen.c:52
Condition variable.
Definition vlc_threads.h:270
struct vlc_cond_waiter * head
Definition vlc_threads.h:271
vlc_mutex_t lock
Definition vlc_threads.h:272
atomic_uint value
Definition threads.c:182
Latch.
Definition vlc_threads.h:447
atomic_uint ready
Definition vlc_threads.h:449
atomic_size_t value
Definition vlc_threads.h:448
Mutex.
Definition vlc_threads.h:143
atomic_uint recursion
Definition vlc_threads.h:148
unsigned int value
Definition vlc_threads.h:153
atomic_uint value
Definition vlc_threads.h:147
atomic_ulong owner
Definition vlc_threads.h:149
unsigned int recursion
Definition vlc_threads.h:154
unsigned long owner
Definition vlc_threads.h:155
One-time initialization.
Definition vlc_threads.h:524
atomic_uint value
Definition vlc_threads.h:525
Semaphore.
Definition vlc_threads.h:368
int dummy
Definition vlc_threads.h:373
atomic_uint value
Definition vlc_threads.h:371
Thread handle.
Definition vlc_threads.h:108
pthread_t handle
Definition vlc_threads.h:109
vlc_tick_t value
Definition timer.c:49
This file is a collection of common definitions and types.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48