58# define ETIMEDOUT 10060
62# define VLC_THREAD_CANCELED ((void*) UINTPTR_MAX)
67static inline int vlc_poll(
struct pollfd *fds,
unsigned nfds,
int timeout)
72 val =
poll(fds, nfds, timeout);
77# define poll(u,n,t) vlc_poll(u, n, t)
79#elif defined (__OS2__)
83#define VLC_THREAD_CANCELED ((void*) UINTPTR_MAX)
88# define pthread_sigmask sigprocmask
90static inline int vlc_poll (
struct pollfd *fds,
unsigned nfds,
int timeout)
92 static int (*vlc_poll_os2)(
struct pollfd *, unsigned, int) = NULL;
97 CHAR szFailed[CCHMAXPATH];
99 if (DosLoadModule(szFailed,
sizeof(szFailed),
"vlccore", &hmod))
102 if (DosQueryProcAddr(hmod, 0,
"_vlc_poll_os2", (PFN *)&vlc_poll_os2))
106 return (*vlc_poll_os2)(fds, nfds, timeout);
108# define poll(u,n,t) vlc_poll(u, n, t)
110#elif defined (__ANDROID__)
114# define LIBVLC_USE_PTHREAD_CLEANUP 1
117#define VLC_THREAD_CANCELED ((void*) UINTPTR_MAX)
121static inline int vlc_poll (
struct pollfd *fds,
unsigned nfds,
int timeout)
127 int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
129 timeout -= ugly_timeout;
132 val =
poll (fds, nfds, ugly_timeout);
134 while (val == 0 && timeout != 0);
139# define poll(u,n,t) vlc_poll(u, n, t)
148# define LIBVLC_USE_PTHREAD 1
153# define LIBVLC_USE_PTHREAD_CLEANUP 1
166#define VLC_THREAD_CANCELED PTHREAD_CANCELED
199 atomic_uint recursion;
205 unsigned int recursion;
217#define VLC_STATIC_MUTEX { \
218 .value = ATOMIC_VAR_INIT(0), \
219 .recursion = ATOMIC_VAR_INIT(0), \
220 .owner = ATOMIC_VAR_INIT(0), \
299#define vlc_mutex_assert(m) assert(vlc_mutex_held(m))
329#define VLC_STATIC_COND { NULL, VLC_STATIC_MUTEX }
586#define VLC_STATIC_QUEUEDMUTEX { ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0) }
609#define vlc_queuedmutex_assert(m) assert(vlc_queuedmutex_held(m))
624#define VLC_STATIC_ONCE { ATOMIC_VAR_INIT(0) }
654 if (
unlikely(atomic_load_explicit(&once->value, memory_order_acquire) < 3))
658#define vlc_once_begin(once) vlc_once_begin_inline(once)
763VLC_WARN_CALL(
"thread name too big")
764const
char * vlc_thread_name_too_big( const
char * thread_name )
769# define check_name_length( thread_name ) \
770 ((__builtin_constant_p(__builtin_strlen(thread_name) > 15) && \
771 __builtin_strlen(thread_name) > 15) \
772 ? vlc_thread_name_too_big(thread_name): thread_name)
784#if defined(check_name_length)
785# define vlc_thread_set_name(name) vlc_thread_set_name(check_name_length(name))
909#define VLC_HARD_MIN_SLEEP VLC_TICK_FROM_MS(10)
910#define VLC_SOFT_MIN_SLEEP VLC_TICK_FROM_SEC(9)
921VLC_ERROR_CALL(
"sorry, cannot sleep for such short a time")
930VLC_WARN_CALL(
"use proper event handling instead of short delay")
936# define check_delay( d ) \
937 ((__builtin_constant_p(d < VLC_HARD_MIN_SLEEP) \
938 && (d < VLC_HARD_MIN_SLEEP)) \
939 ? impossible_delay(d) \
940 : ((__builtin_constant_p(d < VLC_SOFT_MIN_SLEEP) \
941 && (d < VLC_SOFT_MIN_SLEEP)) \
947VLC_ERROR_CALL(
"deadlines can not be constant")
953# define check_deadline( d ) \
954 (__builtin_constant_p(d) ? impossible_deadline(d) : d)
957#if defined(check_delay)
958#define vlc_tick_sleep(d) vlc_tick_sleep(check_delay(d))
960#if defined(check_deadline)
961#define vlc_tick_wait(d) vlc_tick_wait(check_deadline(d))
996#define VLC_TIMER_DISARM (0)
997#define VLC_TIMER_FIRE_ONCE (0)
1051#if defined (LIBVLC_USE_PTHREAD_CLEANUP)
1069# define vlc_cleanup_push( routine, arg ) pthread_cleanup_push (routine, arg)
1077# define vlc_cleanup_pop( ) pthread_cleanup_pop (0)
1083 void (*proc) (
void *);
1092# define vlc_cleanup_push( routine, arg ) \
1094 vlc_control_cancel(&(vlc_cleanup_t){ NULL, routine, arg })
1096# define vlc_cleanup_pop( ) \
1097 vlc_control_cancel (NULL); \
1100# define vlc_cleanup_push(routine, arg) \
1101 static_assert(false, "don't use vlc_cleanup_push in portable C++ code")
1102# define vlc_cleanup_pop() \
1103 static_assert(false, "don't use vlc_cleanup_pop in portable C++ code")
1115class vlc_mutex_locker
1125 ~vlc_mutex_locker (
void)
1157#define vlc_global_lock( n ) vlc_global_mutex(n, true)
1162#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:257
void vlc_cond_signal(vlc_cond_t *)
Wakes up one thread waiting on a condition variable.
Definition: threads.c:204
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:303
void vlc_cond_broadcast(vlc_cond_t *)
Wakes up all threads waiting on a condition variable.
Definition: threads.c:231
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition: threads.c:291
int vlc_cond_timedwait_daytime(vlc_cond_t *, vlc_mutex_t *, time_t)
Definition: threads.c:319
void vlc_cond_init(vlc_cond_t *)
Initializes a condition variable.
Definition: threads.c:185
void vlc_latch_count_down_and_wait(vlc_latch_t *, size_t n)
Decrements the value of a latch and waits on it.
Definition: threads.c:436
void vlc_latch_wait(vlc_latch_t *)
Waits on a latch.
Definition: threads.c:448
void vlc_latch_init(vlc_latch_t *, size_t value)
Initializes a latch.
Definition: threads.c:408
void vlc_latch_count_down(vlc_latch_t *, size_t n)
Decrements the value of a latch.
Definition: threads.c:431
bool vlc_latch_is_ready(const vlc_latch_t *latch)
Checks if a latch is ready.
Definition: threads.c:442
void vlc_mutex_unlock(vlc_mutex_t *)
Releases a mutex.
Definition: threads.c:160
void vlc_mutex_init_recursive(vlc_mutex_t *)
Initializes a recursive mutex.
Definition: threads.c:79
void vlc_mutex_init(vlc_mutex_t *)
Initializes a fast mutex.
Definition: threads.c:74
void vlc_mutex_lock(vlc_mutex_t *)
Acquires a mutex.
Definition: threads.c:106
bool vlc_mutex_held(const vlc_mutex_t *)
Checks if a mutex is locked.
Definition: threads.c:84
int vlc_mutex_trylock(vlc_mutex_t *)
Tries to acquire a mutex.
Definition: threads.c:126
int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline)
Waits on a semaphore within a deadline.
Definition: threads.c:371
int vlc_sem_trywait(vlc_sem_t *sem)
Tries to decrement a semaphore.
Definition: threads.c:392
void vlc_sem_wait(vlc_sem_t *)
Waits on a semaphore.
Definition: threads.c:355
int vlc_sem_post(vlc_sem_t *)
Increments the value of a semaphore.
Definition: threads.c:339
void vlc_sem_init(vlc_sem_t *, unsigned count)
Initializes a semaphore.
Definition: threads.c:334
void vlc_testcancel(void)
Issues an explicit deferred cancellation point.
Definition: thread.c:180
void vlc_global_mutex(unsigned, bool)
Internal handler for global mutexes.
Definition: threads.c:45
static void vlc_once(vlc_once_t *restrict once, void(*cb)(void *), void *opaque)
Executes a function one time.
Definition: vlc_threads.h:693
void vlc_cancel(vlc_thread_t)
Marks a thread as cancelled.
Definition: thread.c:156
bool vlc_queuedmutex_held(vlc_queuedmutex_t *m)
Checks if a queued mutex is locked.
Definition: threads.c:474
void vlc_once_complete(vlc_once_t *restrict once)
Completes a one-time initialization.
Definition: threads.c:532
void vlc_restorecancel(int state)
Restores the cancellation state.
Definition: thread.c:172
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:222
void vlc_queuedmutex_init(vlc_queuedmutex_t *m)
Definition: threads.c:467
void vlc_join(vlc_thread_t th, void **result)
Waits for a thread to complete (if needed), then destroys it.
Definition: thread.c:146
#define vlc_once_begin(once)
Definition: vlc_threads.h:659
int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data)
Creates and starts a new thread.
Definition: thread.c:141
unsigned vlc_GetCPUCount(void)
Count CPUs.
Definition: thread.c:239
void vlc_queuedmutex_unlock(vlc_queuedmutex_t *m)
Definition: threads.c:492
vlc_tick_t vlc_tick_now(void)
Precision monotonic clock.
Definition: thread.c:227
void vlc_control_cancel(vlc_cleanup_t *)
Internal handler for thread cancellation.
Definition: missing.c:270
#define VLC_HARD_MIN_SLEEP
Definition: vlc_threads.h:910
static bool vlc_once_begin_inline(vlc_once_t *restrict once)
Definition: vlc_threads.h:652
void vlc_tick_wait(vlc_tick_t deadline)
Waits until a deadline.
Definition: thread.c:215
int vlc_savecancel(void)
Disables thread cancellation.
Definition: thread.c:162
struct vlc_cleanup_t vlc_cleanup_t
Definition: vlc_threads.h:841
void vlc_thread_set_name(const char *name)
Set the thread name of the current thread.
Definition: thread.c:28
void vlc_queuedmutex_lock(vlc_queuedmutex_t *m)
Definition: threads.c:479
@ VLC_MAX_MUTEX
Definition: vlc_threads.h:1144
@ VLC_GCRYPT_MUTEX
Definition: vlc_threads.h:1137
@ VLC_AVCODEC_MUTEX
Definition: vlc_threads.h:1136
@ VLC_XLIB_MUTEX
Definition: vlc_threads.h:1138
@ VLC_MOSAIC_MUTEX
Definition: vlc_threads.h:1139
pthread_key_t vlc_threadvar_t
Thread-local key handle.
Definition: vlc_threads.h:174
void * vlc_threadvar_get(vlc_threadvar_t)
Gets the value of a thread-local variable for the calling thread.
Definition: thread.c:209
void vlc_threadvar_delete(vlc_threadvar_t *)
Deallocates a thread-specific variable.
Definition: thread.c:199
int vlc_threadvar_set(vlc_threadvar_t key, void *value)
Sets a thread-specific variable.
Definition: thread.c:204
int vlc_threadvar_create(vlc_threadvar_t *key, void(*destr)(void *))
Allocates a thread-specific variable.
Definition: thread.c:194
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:181
static void vlc_timer_disarm(vlc_timer_t timer)
Definition: vlc_threads.h:1021
#define VLC_TIMER_DISARM
Definition: vlc_threads.h:997
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:1026
void vlc_timer_destroy(vlc_timer_t timer)
Destroys an initialized timer.
Definition: thread.c:826
const char name[16]
Definition: httpd.c:1281
vlc_mutex_t lock
Definition: rand.c:33
static thread_local struct @81 state
Definition: fourcc_gen.c:52
Definition: vlc_fixups.h:498
Condition variable.
Definition: vlc_threads.h:322
struct vlc_cond_waiter * head
Definition: vlc_threads.h:323
vlc_mutex_t lock
Definition: vlc_threads.h:324
Definition: threads.c:191
atomic_uint value
Definition: threads.c:193
Latch.
Definition: vlc_threads.h:500
atomic_uint ready
Definition: vlc_threads.h:502
atomic_size_t value
Definition: vlc_threads.h:501
Mutex.
Definition: vlc_threads.h:195
atomic_uint recursion
Definition: vlc_threads.h:200
unsigned int value
Definition: vlc_threads.h:205
atomic_uint value
Definition: vlc_threads.h:199
atomic_ulong owner
Definition: vlc_threads.h:201
unsigned int recursion
Definition: vlc_threads.h:206
unsigned long owner
Definition: vlc_threads.h:207
One-time initialization.
Definition: vlc_threads.h:618
atomic_uint value
Definition: vlc_threads.h:619
Definition: vlc_threads.h:581
atomic_ulong owner
Definition: vlc_threads.h:584
atomic_uint tail
Definition: vlc_threads.h:583
atomic_uint head
Definition: vlc_threads.h:582
Semaphore.
Definition: vlc_threads.h:422
int dummy
Definition: vlc_threads.h:427
atomic_uint value
Definition: vlc_threads.h:425
Thread handle.
Definition: vlc_threads.h:160
pthread_t handle
Definition: vlc_threads.h:161
vlc_tick_t value
Definition: timer.c:49
This file is a collection of common definitions and types.
int poll(struct pollfd *, unsigned, int)
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45