VLC  4.0.0-dev
vlc_threads.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_threads.h : threads implementation for the VideoLAN client
3  * This header provides portable declarations for mutexes & conditions
4  *****************************************************************************
5  * Copyright (C) 1999, 2002 VLC authors and VideoLAN
6  * Copyright © 2007-2016 Rémi Denis-Courmont
7  *
8  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
9  * Samuel Hocevar <sam@via.ecp.fr>
10  * Gildas Bazin <gbazin@netcourrier.com>
11  * Christophe Massiot <massiot@via.ecp.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation; either version 2.1 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27 
28 #ifndef VLC_THREADS_H_
29 #define VLC_THREADS_H_
30 
31 /**
32  * \ingroup os
33  * \defgroup thread Threads and synchronization primitives
34  * @{
35  * \file
36  * Thread primitive declarations
37  */
38 
39 /**
40  * Issues an explicit deferred cancellation point.
41  *
42  * This has no effects if thread cancellation is disabled.
43  * This can be called when there is a rather slow non-sleeping operation.
44  * This is also used to force a cancellation point in a function that would
45  * otherwise <em>not always</em> be one (block_FifoGet() is an example).
46  */
47 VLC_API void vlc_testcancel(void);
48 
49 #if defined (_WIN32)
50 # include <process.h>
51 # ifndef ETIMEDOUT
52 # define ETIMEDOUT 10060 /* This is the value in winsock.h. */
53 # endif
54 
55 typedef struct vlc_thread *vlc_thread_t;
56 # define VLC_THREAD_CANCELED NULL
57 # define LIBVLC_NEED_SLEEP
58 typedef struct
59 {
60  bool dynamic;
61  union
62  {
63  struct
64  {
65  bool locked;
66  unsigned long contention;
67  };
68  CRITICAL_SECTION mutex;
69  };
70 } vlc_mutex_t;
71 #define VLC_STATIC_MUTEX { false, { { false, 0 } } }
72 #define LIBVLC_NEED_CONDVAR
73 #define LIBVLC_NEED_SEMAPHORE
74 #define LIBVLC_NEED_RWLOCK
75 typedef INIT_ONCE vlc_once_t;
76 #define VLC_STATIC_ONCE INIT_ONCE_STATIC_INIT
77 typedef struct vlc_threadvar *vlc_threadvar_t;
78 typedef struct vlc_timer *vlc_timer_t;
79 
80 # define VLC_THREAD_PRIORITY_LOW 0
81 # define VLC_THREAD_PRIORITY_INPUT THREAD_PRIORITY_ABOVE_NORMAL
82 # define VLC_THREAD_PRIORITY_AUDIO THREAD_PRIORITY_HIGHEST
83 # define VLC_THREAD_PRIORITY_VIDEO 0
84 # define VLC_THREAD_PRIORITY_OUTPUT THREAD_PRIORITY_ABOVE_NORMAL
85 # define VLC_THREAD_PRIORITY_HIGHEST THREAD_PRIORITY_TIME_CRITICAL
86 
87 static inline int vlc_poll(struct pollfd *fds, unsigned nfds, int timeout)
88 {
89  int val;
90 
92  val = poll(fds, nfds, timeout);
93  if (val < 0)
95  return val;
96 }
97 # define poll(u,n,t) vlc_poll(u, n, t)
98 
99 #elif defined (__OS2__)
100 # include <errno.h>
101 
102 typedef struct vlc_thread *vlc_thread_t;
103 #define VLC_THREAD_CANCELED NULL
104 typedef struct
105 {
106  bool dynamic;
107  union
108  {
109  struct
110  {
111  bool locked;
112  unsigned long contention;
113  };
114  HMTX hmtx;
115  };
116 } vlc_mutex_t;
117 #define VLC_STATIC_MUTEX { false, { { false, 0 } } }
118 typedef struct
119 {
120  HEV hev;
121  unsigned waiters;
122  HEV hevAck;
123  unsigned signaled;
124 } vlc_cond_t;
125 #define VLC_STATIC_COND { NULLHANDLE, 0, NULLHANDLE, 0 }
126 #define LIBVLC_NEED_SEMAPHORE
127 #define LIBVLC_NEED_RWLOCK
128 typedef struct
129 {
130  unsigned done;
131  vlc_mutex_t mutex;
132 } vlc_once_t;
133 #define VLC_STATIC_ONCE { 0, VLC_STATIC_MUTEX }
134 typedef struct vlc_threadvar *vlc_threadvar_t;
135 typedef struct vlc_timer *vlc_timer_t;
136 
137 # define VLC_THREAD_PRIORITY_LOW 0
138 # define VLC_THREAD_PRIORITY_INPUT \
139  MAKESHORT(PRTYD_MAXIMUM / 2, PRTYC_REGULAR)
140 # define VLC_THREAD_PRIORITY_AUDIO MAKESHORT(PRTYD_MAXIMUM, PRTYC_REGULAR)
141 # define VLC_THREAD_PRIORITY_VIDEO 0
142 # define VLC_THREAD_PRIORITY_OUTPUT \
143  MAKESHORT(PRTYD_MAXIMUM / 2, PRTYC_REGULAR)
144 # define VLC_THREAD_PRIORITY_HIGHEST MAKESHORT(0, PRTYC_TIMECRITICAL)
145 
146 # define pthread_sigmask sigprocmask
147 
148 static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
149 {
150  static int (*vlc_poll_os2)(struct pollfd *, unsigned, int) = NULL;
151 
152  if (!vlc_poll_os2)
153  {
154  HMODULE hmod;
155  CHAR szFailed[CCHMAXPATH];
156 
157  if (DosLoadModule(szFailed, sizeof(szFailed), "vlccore", &hmod))
158  return -1;
159 
160  if (DosQueryProcAddr(hmod, 0, "_vlc_poll_os2", (PFN *)&vlc_poll_os2))
161  return -1;
162  }
163 
164  return (*vlc_poll_os2)(fds, nfds, timeout);
165 }
166 # define poll(u,n,t) vlc_poll(u, n, t)
167 
168 #elif defined (__ANDROID__) /* pthreads subset without pthread_cancel() */
169 # include <unistd.h>
170 # include <pthread.h>
171 # include <poll.h>
172 # define LIBVLC_USE_PTHREAD_CLEANUP 1
173 # define LIBVLC_NEED_SLEEP
174 # define LIBVLC_NEED_CONDVAR
175 # define LIBVLC_NEED_SEMAPHORE
176 # define LIBVLC_NEED_RWLOCK
177 
178 typedef struct vlc_thread *vlc_thread_t;
179 #define VLC_THREAD_CANCELED NULL
180 typedef pthread_mutex_t vlc_mutex_t;
181 #define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
182 typedef pthread_once_t vlc_once_t;
183 #define VLC_STATIC_ONCE PTHREAD_ONCE_INIT
184 typedef pthread_key_t vlc_threadvar_t;
185 typedef struct vlc_timer *vlc_timer_t;
186 
187 # define VLC_THREAD_PRIORITY_LOW 0
188 # define VLC_THREAD_PRIORITY_INPUT 0
189 # define VLC_THREAD_PRIORITY_AUDIO 0
190 # define VLC_THREAD_PRIORITY_VIDEO 0
191 # define VLC_THREAD_PRIORITY_OUTPUT 0
192 # define VLC_THREAD_PRIORITY_HIGHEST 0
193 
194 static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
195 {
196  int val;
197 
198  do
199  {
200  int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
201  if (timeout >= 0)
202  timeout -= ugly_timeout;
203 
204  vlc_testcancel ();
205  val = poll (fds, nfds, ugly_timeout);
206  }
207  while (val == 0 && timeout != 0);
208 
209  return val;
210 }
211 
212 # define poll(u,n,t) vlc_poll(u, n, t)
213 
214 #elif defined (__APPLE__)
215 # define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
216 # include <unistd.h>
217 # include <pthread.h>
218 /* Unnamed POSIX semaphores not supported on Mac OS X */
219 # include <mach/semaphore.h>
220 # include <mach/task.h>
221 # define LIBVLC_USE_PTHREAD_CLEANUP 1
222 
223 typedef pthread_t vlc_thread_t;
224 #define VLC_THREAD_CANCELED PTHREAD_CANCELED
225 typedef pthread_mutex_t vlc_mutex_t;
226 #define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
227 typedef pthread_cond_t vlc_cond_t;
228 #define VLC_STATIC_COND PTHREAD_COND_INITIALIZER
229 typedef semaphore_t vlc_sem_t;
230 typedef pthread_rwlock_t vlc_rwlock_t;
231 #define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
232 typedef pthread_once_t vlc_once_t;
233 #define VLC_STATIC_ONCE PTHREAD_ONCE_INIT
234 typedef pthread_key_t vlc_threadvar_t;
235 typedef struct vlc_timer *vlc_timer_t;
236 
237 # define VLC_THREAD_PRIORITY_LOW 0
238 # define VLC_THREAD_PRIORITY_INPUT 22
239 # define VLC_THREAD_PRIORITY_AUDIO 22
240 # define VLC_THREAD_PRIORITY_VIDEO 0
241 # define VLC_THREAD_PRIORITY_OUTPUT 22
242 # define VLC_THREAD_PRIORITY_HIGHEST 22
243 
244 #else /* POSIX threads */
245 # include <unistd.h> /* _POSIX_SPIN_LOCKS */
246 # include <pthread.h>
247 # include <semaphore.h>
248 
249 /**
250  * Whether LibVLC threads are based on POSIX threads.
251  */
252 # define LIBVLC_USE_PTHREAD 1
254 /**
255  * Whether LibVLC thread cancellation is based on POSIX threads.
256  */
257 # define LIBVLC_USE_PTHREAD_CLEANUP 1
259 /**
260  * Thread handle.
261  */
262 typedef struct
263 {
264  pthread_t handle;
265 } vlc_thread_t;
266 
267 /**
268  * Return value of a canceled thread.
269  */
270 #define VLC_THREAD_CANCELED PTHREAD_CANCELED
272 /**
273  * Mutex.
274  *
275  * Storage space for a mutual exclusion lock.
276  */
277 typedef pthread_mutex_t vlc_mutex_t;
279 /**
280  * Static initializer for (static) mutex.
281  */
282 #define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
284 /**
285  * Condition variable.
286  *
287  * Storage space for a thread condition variable.
288  */
289 typedef pthread_cond_t vlc_cond_t;
291 /**
292  * Static initializer for (static) condition variable.
293  *
294  * \note
295  * The condition variable will use the default clock, which is OS-dependent.
296  * Therefore, where timed waits are necessary the condition variable should
297  * always be initialized dynamically explicit instead of using this
298  * initializer.
299  */
300 #define VLC_STATIC_COND PTHREAD_COND_INITIALIZER
302 /**
303  * Semaphore.
304  *
305  * Storage space for a thread-safe semaphore.
306  */
307 typedef sem_t vlc_sem_t;
309 /**
310  * Read/write lock.
311  *
312  * Storage space for a slim reader/writer lock.
313  */
314 typedef pthread_rwlock_t vlc_rwlock_t;
316 /**
317  * Static initializer for (static) read/write lock.
318  */
319 #define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
321 /**
322  * One-time initialization.
323  *
324  * A one-time initialization object must always be initialized assigned to
325  * \ref VLC_STATIC_ONCE before use.
326  */
327 typedef pthread_once_t vlc_once_t;
329 /**
330  * Static initializer for one-time initialization.
331  */
332 #define VLC_STATIC_ONCE PTHREAD_ONCE_INIT
334 /**
335  * Thread-local key handle.
336  */
337 typedef pthread_key_t vlc_threadvar_t;
339 /**
340  * Threaded timer handle.
341  */
342 typedef struct vlc_timer *vlc_timer_t;
344 # define VLC_THREAD_PRIORITY_LOW 0
345 # define VLC_THREAD_PRIORITY_INPUT 10
346 # define VLC_THREAD_PRIORITY_AUDIO 5
347 # define VLC_THREAD_PRIORITY_VIDEO 0
348 # define VLC_THREAD_PRIORITY_OUTPUT 15
349 # define VLC_THREAD_PRIORITY_HIGHEST 20
351 #endif
352 
353 #ifdef LIBVLC_NEED_CONDVAR
354 typedef struct
355 {
356  unsigned value;
357 } vlc_cond_t;
358 # define VLC_STATIC_COND { 0 }
359 #endif
360 
361 #ifdef LIBVLC_NEED_SEMAPHORE
362 typedef struct vlc_sem
363 {
364  vlc_mutex_t lock;
365  vlc_cond_t wait;
366  unsigned value;
367 } vlc_sem_t;
368 #endif
369 
370 #ifdef LIBVLC_NEED_RWLOCK
371 typedef struct vlc_rwlock
372 {
373  vlc_mutex_t mutex;
374  vlc_cond_t wait;
375  long state;
376 } vlc_rwlock_t;
377 # define VLC_STATIC_RWLOCK { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0 }
378 #endif
379 
380 /**
381  * Initializes a fast mutex.
382  *
383  * Recursive locking of a fast mutex is undefined behaviour. (In debug builds,
384  * recursive locking will cause an assertion failure.)
385  */
386 VLC_API void vlc_mutex_init(vlc_mutex_t *);
387 
388 /**
389  * Initializes a recursive mutex.
390  * \warning This is strongly discouraged. Please use normal mutexes.
391  */
392 VLC_API void vlc_mutex_init_recursive(vlc_mutex_t *);
393 
394 /**
395  * Deinitializes a mutex.
396  *
397  * The mutex must not be locked, otherwise behaviour is undefined.
398  */
399 VLC_API void vlc_mutex_destroy(vlc_mutex_t *);
400 
401 /**
402  * Acquires a mutex.
403  *
404  * If needed, this waits for any other thread to release it.
405  *
406  * \warning Beware of deadlocks when locking multiple mutexes at the same time,
407  * or when using mutexes from callbacks.
408  *
409  * \note This function is not a cancellation point.
410  */
411 VLC_API void vlc_mutex_lock(vlc_mutex_t *);
412 
413 /**
414  * Tries to acquire a mutex.
415  *
416  * This function acquires the mutex if and only if it is not currently held by
417  * another thread. This function never sleeps and can be used in delay-critical
418  * code paths.
419  *
420  * \note This function is not a cancellation point.
421  *
422  * \warning If this function fails, then the mutex is held... by another
423  * thread. The calling thread must deal with the error appropriately. That
424  * typically implies postponing the operations that would have required the
425  * mutex. If the thread cannot defer those operations, then it must use
426  * vlc_mutex_lock(). If in doubt, use vlc_mutex_lock() instead.
427  *
428  * @return 0 if the mutex could be acquired, an error code otherwise.
429  */
430 VLC_API int vlc_mutex_trylock( vlc_mutex_t * ) VLC_USED;
431 
432 /**
433  * Releases a mutex.
434  *
435  * If the mutex is not held by the calling thread, the behaviour is undefined.
436  *
437  * \note This function is not a cancellation point.
438  */
439 VLC_API void vlc_mutex_unlock(vlc_mutex_t *);
440 
441 /**
442  * Checks if a mutex is locked.
443  *
444  * Do not use this function directly. Use vlc_mutex_assert() instead.
445  *
446  * @note
447  * This function has no effects.
448  * It is only meant to be use in run-time assertions.
449  *
450  * @retval false in debug builds of LibVLC,
451  * if the mutex is not locked by the calling thread;
452  * @retval true in debug builds of LibVLC,
453  * if the mutex is locked by the calling thread;
454  * @retval true in release builds of LibVLC.
455  */
456 VLC_API bool vlc_mutex_marked(const vlc_mutex_t *) VLC_USED;
457 
458 /**
459  * Asserts that a mutex is locked by the calling thread.
460  */
461 #define vlc_mutex_assert(m) assert(vlc_mutex_marked(m))
463 /**
464  * Initializes a condition variable.
465  */
466 VLC_API void vlc_cond_init(vlc_cond_t *);
467 
468 /**
469  * Initializes a condition variable (wall clock).
470  *
471  * This function initializes a condition variable for timed waiting using the
472  * UTC wall clock time. The time reference is the same as with time() and with
473  * timespec_get() and TIME_UTC.
474  * vlc_cond_timedwait_daytime() must be instead of
475  * vlc_cond_timedwait() for actual waiting.
476  */
477 void vlc_cond_init_daytime(vlc_cond_t *);
478 
479 /**
480  * Deinitializes a condition variable.
481  *
482  * No threads shall be waiting or signaling the condition, otherwise the
483  * behavior is undefined.
484  */
485 VLC_API void vlc_cond_destroy(vlc_cond_t *);
486 
487 /**
488  * Wakes up one thread waiting on a condition variable.
489  *
490  * If any thread is currently waiting on the condition variable, at least one
491  * of those threads will be woken up. Otherwise, this function has no effects.
492  *
493  * \note This function is not a cancellation point.
494  */
495 VLC_API void vlc_cond_signal(vlc_cond_t *);
496 
497 /**
498  * Wakes up all threads waiting on a condition variable.
499  *
500  * \note This function is not a cancellation point.
501  */
502 VLC_API void vlc_cond_broadcast(vlc_cond_t *);
503 
504 /**
505  * Waits on a condition variable.
506  *
507  * The calling thread will be suspended until another thread calls
508  * vlc_cond_signal() or vlc_cond_broadcast() on the same condition variable,
509  * the thread is cancelled with vlc_cancel(), or the system causes a
510  * <em>spurious</em> unsolicited wake-up.
511  *
512  * A mutex is needed to wait on a condition variable. It must <b>not</b> be
513  * a recursive mutex. Although it is possible to use the same mutex for
514  * multiple condition, it is not valid to use different mutexes for the same
515  * condition variable at the same time from different threads.
516  *
517  * The canonical way to use a condition variable to wait for event foobar is:
518  @code
519  vlc_mutex_lock(&lock);
520  mutex_cleanup_push(&lock); // release the mutex in case of cancellation
521 
522  while (!foobar)
523  vlc_cond_wait(&wait, &lock);
524 
525  // -- foobar is now true, do something about it here --
526 
527  vlc_cleanup_pop();
528  vlc_mutex_unlock(&lock);
529  @endcode
530  *
531  * \note This function is a cancellation point. In case of thread cancellation,
532  * the mutex is always locked before cancellation proceeds.
533  *
534  * \param cond condition variable to wait on
535  * \param mutex mutex which is unlocked while waiting,
536  * then locked again when waking up.
537  */
538 VLC_API void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex);
539 
540 /**
541  * Waits on a condition variable up to a certain date.
542  *
543  * This works like vlc_cond_wait() but with an additional time-out.
544  * The time-out is expressed as an absolute timestamp using the same arbitrary
545  * time reference as the vlc_tick_now() and vlc_tick_wait() functions.
546  *
547  * \note This function is a cancellation point. In case of thread cancellation,
548  * the mutex is always locked before cancellation proceeds.
549  *
550  * \param cond condition variable to wait on
551  * \param mutex mutex which is unlocked while waiting,
552  * then locked again when waking up
553  * \param deadline <b>absolute</b> timeout
554  *
555  * \warning If the variable was initialized with vlc_cond_init_daytime(), or
556  * was statically initialized with \ref VLC_STATIC_COND, the time reference
557  * used by this function is unspecified (depending on the implementation, it
558  * might be the Unix epoch or the vlc_tick_now() clock).
559  *
560  * \return 0 if the condition was signaled, an error code in case of timeout.
561  */
562 VLC_API int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex,
563  vlc_tick_t deadline);
564 
565 int vlc_cond_timedwait_daytime(vlc_cond_t *, vlc_mutex_t *, time_t);
566 
567 /**
568  * Initializes a semaphore.
569  *
570  * @param count initial semaphore value (typically 0)
571  */
572 VLC_API void vlc_sem_init(vlc_sem_t *, unsigned count);
573 
574 /**
575  * Deinitializes a semaphore.
576  */
577 VLC_API void vlc_sem_destroy(vlc_sem_t *);
578 
579 /**
580  * Increments the value of a semaphore.
581  *
582  * \note This function is not a cancellation point.
583  *
584  * \return 0 on success, EOVERFLOW in case of integer overflow.
585  */
586 VLC_API int vlc_sem_post(vlc_sem_t *);
587 
588 /**
589  * Waits on a semaphore.
590  *
591  * This function atomically waits for the semaphore to become non-zero then
592  * decrements it, and returns. If the semaphore is non-zero on entry, it is
593  * immediately decremented.
594  *
595  * \note This function may be a point of cancellation.
596  */
597 VLC_API void vlc_sem_wait(vlc_sem_t *);
598 
599 /**
600  * Initializes a read/write lock.
601  */
602 VLC_API void vlc_rwlock_init(vlc_rwlock_t *);
603 
604 /**
605  * Destroys an initialized unused read/write lock.
606  */
607 VLC_API void vlc_rwlock_destroy(vlc_rwlock_t *);
608 
609 /**
610  * Acquires a read/write lock for reading.
611  *
612  * \note Recursion is allowed.
613  * \note This function may be a point of cancellation.
614  */
615 VLC_API void vlc_rwlock_rdlock(vlc_rwlock_t *);
616 
617 /**
618  * Acquires a read/write lock for writing. Recursion is not allowed.
619  * \note This function may be a point of cancellation.
620  */
621 VLC_API void vlc_rwlock_wrlock(vlc_rwlock_t *);
622 
623 /**
624  * Releases a read/write lock.
625  *
626  * The calling thread must hold the lock. Otherwise behaviour is undefined.
627  *
628  * \note This function is not a cancellation point.
629  */
630 VLC_API void vlc_rwlock_unlock(vlc_rwlock_t *);
631 
632 /**
633  * Executes a function one time.
634  *
635  * The first time this function is called with a given one-time initialization
636  * object, it executes the provided callback.
637  * Any further call with the same object will be a no-op.
638  *
639  * In the corner case that the first time execution is ongoing in another
640  * thread, then the function will wait for completion on the other thread
641  * (and then synchronize memory) before it returns.
642  * This ensures that, no matter what, the callback has been executed exactly
643  * once and its side effects are visible after the function returns.
644  *
645  * \param once a one-time initialization object
646  * \param cb callback to execute (the first time)
647  */
648 VLC_API void vlc_once(vlc_once_t *restrict once, void (*cb)(void));
649 
650 /**
651  * Allocates a thread-specific variable.
652  *
653  * @param key where to store the thread-specific variable handle
654  * @param destr a destruction callback. It is called whenever a thread exits
655  * and the thread-specific variable has a non-NULL value.
656  *
657  * @return 0 on success, a system error code otherwise.
658  * This function can actually fail: on most systems, there is a fixed limit to
659  * the number of thread-specific variables in a given process.
660  */
661 VLC_API int vlc_threadvar_create(vlc_threadvar_t *key, void (*destr) (void *));
662 
663 /**
664  * Deallocates a thread-specific variable.
665  */
666 VLC_API void vlc_threadvar_delete(vlc_threadvar_t *);
667 
668 /**
669  * Sets a thread-specific variable.
670 
671  * \param key thread-local variable key (created with vlc_threadvar_create())
672  * \param value new value for the variable for the calling thread
673  * \return 0 on success, a system error code otherwise.
674  */
675 VLC_API int vlc_threadvar_set(vlc_threadvar_t key, void *value);
676 
677 /**
678  * Gets the value of a thread-local variable for the calling thread.
679  * This function cannot fail.
680  *
681  * \return the value associated with the given variable for the calling
682  * or NULL if no value was set.
683  */
684 VLC_API void *vlc_threadvar_get(vlc_threadvar_t);
685 
686 /**
687  * Waits on an address.
688  *
689  * Puts the calling thread to sleep if a specific value is stored at a
690  * specified address. The thread will sleep until it is woken up by a call to
691  * vlc_addr_signal() or vlc_addr_broadcast() in another thread, or spuriously.
692  *
693  * If the value does not match, do nothing and return immediately.
694  *
695  * \param addr address to check for
696  * \param val value to match at the address
697  */
698 void vlc_addr_wait(void *addr, unsigned val);
699 
700 /**
701  * Waits on an address with a time-out.
702  *
703  * This function operates as vlc_addr_wait() but provides an additional
704  * time-out. If the time-out elapses, the thread resumes and the function
705  * returns.
706  *
707  * \param addr address to check for
708  * \param val value to match at the address
709  * \param delay time-out duration
710  *
711  * \return true if the function was woken up before the time-out,
712  * false if the time-out elapsed.
713  */
714 bool vlc_addr_timedwait(void *addr, unsigned val, vlc_tick_t delay);
715 
716 /**
717  * Wakes up one thread on an address.
718  *
719  * Wakes up (at least) one of the thread sleeping on the specified address.
720  * The address must be equal to the first parameter given by at least one
721  * thread sleeping within the vlc_addr_wait() or vlc_addr_timedwait()
722  * functions. If no threads are found, this function does nothing.
723  *
724  * \param addr address identifying which threads may be woken up
725  */
726 void vlc_addr_signal(void *addr);
727 
728 /**
729  * Wakes up all thread on an address.
730  *
731  * Wakes up all threads sleeping on the specified address (if any).
732  * Any thread sleeping within a call to vlc_addr_wait() or vlc_addr_timedwait()
733  * with the specified address as first call parameter will be woken up.
734  *
735  * \param addr address identifying which threads to wake up
736  */
737 void vlc_addr_broadcast(void *addr);
738 
739 /**
740  * Creates and starts a new thread.
741  *
742  * The thread must be <i>joined</i> with vlc_join() to reclaim resources
743  * when it is not needed anymore.
744  *
745  * @param th storage space for the handle of the new thread (cannot be NULL)
746  * [OUT]
747  * @param entry entry point for the thread
748  * @param data data parameter given to the entry point
749  * @param priority thread priority value
750  * @return 0 on success, a standard error code on error.
751  * @note In case of error, the value of *th is undefined.
752  */
753 VLC_API int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data,
754  int priority) VLC_USED;
755 
756 /**
757  * Marks a thread as cancelled.
758  *
759  * Next time the target thread reaches a cancellation point (while not having
760  * disabled cancellation), it will run its cancellation cleanup handler, the
761  * thread variable destructors, and terminate.
762  *
763  * vlc_join() must be used regardless of a thread being cancelled or not, to
764  * avoid leaking resources.
765  */
766 VLC_API void vlc_cancel(vlc_thread_t);
767 
768 /**
769  * Waits for a thread to complete (if needed), then destroys it.
770  *
771  * \note This is a cancellation point. In case of cancellation, the thread is
772  * <b>not</b> joined.
773 
774  * \warning A thread cannot join itself (normally VLC will abort if this is
775  * attempted). Also a detached thread <b>cannot</b> be joined.
776  *
777  * @param th thread handle
778  * @param result [OUT] pointer to write the thread return value or NULL
779  */
780 VLC_API void vlc_join(vlc_thread_t th, void **result);
781 
782 /**
783  * Disables thread cancellation.
784  *
785  * This functions saves the current cancellation state (enabled or disabled),
786  * then disables cancellation for the calling thread. It must be called before
787  * entering a piece of code that is not cancellation-safe, unless it can be
788  * proven that the calling thread will not be cancelled.
789  *
790  * \note This function is not a cancellation point.
791  *
792  * \return Previous cancellation state (opaque value for vlc_restorecancel()).
793  */
794 VLC_API int vlc_savecancel(void);
795 
796 /**
797  * Restores the cancellation state.
798  *
799  * This function restores the cancellation state of the calling thread to
800  * a state previously saved by vlc_savecancel().
801  *
802  * \note This function is not a cancellation point.
803  *
804  * \param state previous state as returned by vlc_savecancel().
805  */
807 
808 /**
809  * Internal handler for thread cancellation.
810  *
811  * Do not call this function directly. Use wrapper macros instead:
812  * vlc_cleanup_push(), vlc_cleanup_pop().
813  */
814 VLC_API void vlc_control_cancel(int cmd, ...);
815 
816 /**
817  * Thread handle.
818  *
819  * This function returns the thread handle of the calling thread.
820  *
821  * \note The exact type of the thread handle depends on the platform,
822  * including an integer type, a pointer type or a compound type of any size.
823  * If you need an integer identifier, use vlc_thread_id() instead.
824  *
825  * \note vlc_join(vlc_thread_self(), NULL) is undefined,
826  * as it obviously does not make any sense (it might result in a deadlock, but
827  * there are no warranties that it will).
828  *
829  * \return the thread handle
830  */
831 VLC_API vlc_thread_t vlc_thread_self(void) VLC_USED;
832 
833 /**
834  * Thread identifier.
835  *
836  * This function returns the identifier of the calling thread. The identifier
837  * cannot change for the entire duration of the thread, and no other thread can
838  * have the same identifier at the same time in the same process. Typically,
839  * the identifier is also unique across all running threads of all existing
840  * processes, but that depends on the operating system.
841  *
842  * There are no particular semantics to the thread ID with LibVLC.
843  * It is provided mainly for tracing and debugging.
844  *
845  * \warning This function is not currently implemented on all supported
846  * platforms. Where not implemented, it returns (unsigned long)-1.
847  *
848  * \return the thread identifier (or -1 if unimplemented)
849  */
850 VLC_API unsigned long vlc_thread_id(void) VLC_USED;
851 
852 /**
853  * Precision monotonic clock.
854  *
855  * In principles, the clock has a precision of 1 MHz. But the actual resolution
856  * may be much lower, especially when it comes to sleeping with vlc_tick_wait() or
857  * vlc_tick_sleep(). Most general-purpose operating systems provide a resolution of
858  * only 100 to 1000 Hz.
859  *
860  * \warning The origin date (time value "zero") is not specified. It is
861  * typically the time the kernel started, but this is platform-dependent.
862  * If you need wall clock time, use gettimeofday() instead.
863  *
864  * \return a timestamp in microseconds.
865  */
867 
868 /**
869  * Waits until a deadline.
870  *
871  * \param deadline timestamp to wait for (\ref vlc_tick_now())
872  *
873  * \note The deadline may be exceeded due to OS scheduling.
874  * \note This function is a cancellation point.
875  */
876 VLC_API void vlc_tick_wait(vlc_tick_t deadline);
877 
878 /**
879  * Waits for an interval of time.
880  *
881  * \param delay how long to wait (in microseconds)
882  *
883  * \note The delay may be exceeded due to OS scheduling.
884  * \note This function is a cancellation point.
885  */
886 VLC_API void vlc_tick_sleep(vlc_tick_t delay);
887 
888 #define VLC_HARD_MIN_SLEEP VLC_TICK_FROM_MS(10) /* 10 milliseconds = 1 tick at 100Hz */
889 #define VLC_SOFT_MIN_SLEEP VLC_TICK_FROM_SEC(9) /* 9 seconds */
891 #if defined (__GNUC__) && !defined (__clang__)
892 /* Linux has 100, 250, 300 or 1000Hz
893  *
894  * HZ=100 by default on FreeBSD, but some architectures use a 1000Hz timer
895  */
896 
897 static
898 __attribute__((unused))
899 __attribute__((noinline))
900 __attribute__((error("sorry, cannot sleep for such short a time")))
901 vlc_tick_t impossible_delay( vlc_tick_t delay )
902 {
903  (void) delay;
904  return VLC_HARD_MIN_SLEEP;
905 }
906 
907 static
908 __attribute__((unused))
909 __attribute__((noinline))
910 __attribute__((warning("use proper event handling instead of short delay")))
911 vlc_tick_t harmful_delay( vlc_tick_t delay )
912 {
913  return delay;
914 }
915 
916 # define check_delay( d ) \
917  ((__builtin_constant_p(d < VLC_HARD_MIN_SLEEP) \
918  && (d < VLC_HARD_MIN_SLEEP)) \
919  ? impossible_delay(d) \
920  : ((__builtin_constant_p(d < VLC_SOFT_MIN_SLEEP) \
921  && (d < VLC_SOFT_MIN_SLEEP)) \
922  ? harmful_delay(d) \
923  : d))
924 
925 static
926 __attribute__((unused))
927 __attribute__((noinline))
928 __attribute__((error("deadlines can not be constant")))
929 vlc_tick_t impossible_deadline( vlc_tick_t deadline )
930 {
931  return deadline;
932 }
933 
934 # define check_deadline( d ) \
935  (__builtin_constant_p(d) ? impossible_deadline(d) : d)
936 #else
937 # define check_delay(d) (d)
938 # define check_deadline(d) (d)
939 #endif
940 
941 #define vlc_tick_sleep(d) vlc_tick_sleep(check_delay(d))
942 #define vlc_tick_wait(d) vlc_tick_wait(check_deadline(d))
944 /**
945  * Initializes an asynchronous timer.
946  *
947  * \param id pointer to timer to be initialized
948  * \param func function that the timer will call
949  * \param data parameter for the timer function
950  * \return 0 on success, a system error code otherwise.
951  *
952  * \warning Asynchronous timers are processed from an unspecified thread.
953  * \note Multiple occurrences of a single interval timer are serialized:
954  * they cannot run concurrently.
955  */
956 VLC_API int vlc_timer_create(vlc_timer_t *id, void (*func)(void *), void *data)
957 VLC_USED;
958 
959 /**
960  * Destroys an initialized timer.
961  *
962  * If needed, the timer is first disarmed. Behaviour is undefined if the
963  * specified timer is not initialized.
964  *
965  * \warning This function <b>must</b> be called before the timer data can be
966  * freed and before the timer callback function can be unmapped/unloaded.
967  *
968  * \param timer timer to destroy
969  */
970 VLC_API void vlc_timer_destroy(vlc_timer_t timer);
971 
972 #define VLC_TIMER_DISARM (0)
973 #define VLC_TIMER_FIRE_ONCE (0)
975 /**
976  * Arms or disarms an initialized timer.
977  *
978  * This functions overrides any previous call to itself.
979  *
980  * \note A timer can fire later than requested due to system scheduling
981  * limitations. An interval timer can fail to trigger sometimes, either because
982  * the system is busy or suspended, or because a previous iteration of the
983  * timer is still running. See also vlc_timer_getoverrun().
984  *
985  * \param timer initialized timer
986  * \param absolute the timer value origin is the same as vlc_tick_now() if true,
987  * the timer value is relative to now if false.
988  * \param value zero to disarm the timer, otherwise the initial time to wait
989  * before firing the timer.
990  * \param interval zero to fire the timer just once, otherwise the timer
991  * repetition interval.
992  */
993 VLC_API void vlc_timer_schedule(vlc_timer_t timer, bool absolute,
994  vlc_tick_t value, vlc_tick_t interval);
995 
996 static inline void vlc_timer_disarm(vlc_timer_t timer)
997 {
998  vlc_timer_schedule( timer, false, VLC_TIMER_DISARM, 0 );
999 }
1000 
1001 static inline void vlc_timer_schedule_asap(vlc_timer_t timer, vlc_tick_t interval)
1003  vlc_timer_schedule(timer, false, 1, interval);
1004 }
1005 
1006 /**
1007  * Fetches and resets the overrun counter for a timer.
1008  *
1009  * This functions returns the number of times that the interval timer should
1010  * have fired, but the callback was not invoked due to scheduling problems.
1011  * The call resets the counter to zero.
1012  *
1013  * \param timer initialized timer
1014  * \return the timer overrun counter (typically zero)
1015  */
1016 VLC_API unsigned vlc_timer_getoverrun(vlc_timer_t) VLC_USED;
1017 
1018 /**
1019  * Count CPUs.
1020  *
1021  * \return number of available (logical) CPUs.
1022  */
1023 VLC_API unsigned vlc_GetCPUCount(void);
1024 
1025 enum
1026 {
1031 };
1032 
1033 #if defined (LIBVLC_USE_PTHREAD_CLEANUP)
1034 /**
1035  * Registers a thread cancellation handler.
1036  *
1037  * This pushes a function to run if the thread is cancelled (or otherwise
1038  * exits prematurely).
1039  *
1040  * If multiple procedures are registered,
1041  * they are handled in last-in first-out order.
1042  *
1043  * \note Any call to vlc_cleanup_push() <b>must</b> paired with a call to
1044  * vlc_cleanup_pop().
1045  * \warning Branching into or out of the block between these two function calls
1046  * is not allowed (read: it will likely crash the whole process).
1047  *
1048  * \param routine procedure to call if the thread ends
1049  * \param arg argument for the procedure
1050  */
1051 # define vlc_cleanup_push( routine, arg ) pthread_cleanup_push (routine, arg)
1053 /**
1054  * Unregisters the last cancellation handler.
1055  *
1056  * This pops the cancellation handler that was last pushed with
1057  * vlc_cleanup_push() in the calling thread.
1058  */
1059 # define vlc_cleanup_pop( ) pthread_cleanup_pop (0)
1061 #else
1062 typedef struct vlc_cleanup_t vlc_cleanup_t;
1063 
1064 struct vlc_cleanup_t
1065 {
1066  vlc_cleanup_t *next;
1067  void (*proc) (void *);
1068  void *data;
1069 };
1070 
1071 # ifndef __cplusplus
1072 /* This macros opens a code block on purpose: It reduces the chance of
1073  * not pairing the push and pop. It also matches the POSIX Thread internals.
1074  * That way, Win32 developers will not accidentally break other platforms.
1075  */
1076 # define vlc_cleanup_push( routine, arg ) \
1077  do { \
1078  vlc_control_cancel(VLC_CLEANUP_PUSH, \
1079  &(vlc_cleanup_t){ NULL, routine, arg })
1080 
1081 # define vlc_cleanup_pop( ) \
1082  vlc_control_cancel (VLC_CLEANUP_POP); \
1083  } while (0)
1084 # else
1085 /* Those macros do not work in C++. However common C/C++ helpers may call them
1086  * anyway - this is fine if the code is never cancelled in C++ case.
1087  * So define the macros to do nothing.
1088  */
1089 # define vlc_cleanup_push(routine, arg) do { (routine, arg)
1090 # define vlc_cleanup_pop() } while (0)
1091 # endif
1092 
1093 #endif /* !LIBVLC_USE_PTHREAD_CLEANUP */
1094 
1095 static inline void vlc_cleanup_lock (void *lock)
1097  vlc_mutex_unlock ((vlc_mutex_t *)lock);
1098 }
1099 #define mutex_cleanup_push( lock ) vlc_cleanup_push (vlc_cleanup_lock, lock)
1101 static inline void vlc_cancel_addr_set(void *addr)
1104 }
1105 
1106 static inline void vlc_cancel_addr_clear(void *addr)
1109 }
1110 
1111 #ifdef __cplusplus
1112 /**
1113  * Helper C++ class to lock a mutex.
1114  *
1115  * The mutex is locked when the object is created, and unlocked when the object
1116  * is destroyed.
1117  */
1118 class vlc_mutex_locker
1119 {
1120  private:
1121  vlc_mutex_t *lock;
1122  public:
1123  vlc_mutex_locker (vlc_mutex_t *m) : lock (m)
1124  {
1125  vlc_mutex_lock (lock);
1126  }
1127 
1128  ~vlc_mutex_locker (void)
1129  {
1130  vlc_mutex_unlock (lock);
1131  }
1132 };
1133 
1134 #endif
1135 
1136 enum
1137 {
1138  VLC_AVCODEC_MUTEX = 0,
1142 #ifdef _WIN32
1143  VLC_MTA_MUTEX,
1144 #endif
1145  /* Insert new entry HERE */
1147 };
1148 
1149 /**
1150  * Internal handler for global mutexes.
1151  *
1152  * Do not use this function directly. Use helper macros instead:
1153  * vlc_global_lock(), vlc_global_unlock().
1154  */
1155 VLC_API void vlc_global_mutex(unsigned, bool);
1156 
1157 /**
1158  * Acquires a global mutex.
1159  */
1160 #define vlc_global_lock( n ) vlc_global_mutex(n, true)
1162 /**
1163  * Releases a global mutex.
1164  */
1165 #define vlc_global_unlock( n ) vlc_global_mutex(n, false)
1167 /** @} */
1168 
1169 #endif /* !_VLC_THREADS_H */
int vlc_threadvar_set(vlc_threadvar_t key, void *value)
Sets a thread-specific variable.
Definition: thread.c:398
bool vlc_mutex_marked(const vlc_mutex_t *)
Checks if a mutex is locked.
Definition: threads.c:132
pthread_once_t vlc_once_t
One-time initialization.
Definition: vlc_threads.h:328
void vlc_cancel(vlc_thread_t)
Marks a thread as cancelled.
Definition: thread.c:300
void vlc_cond_signal(vlc_cond_t *)
Wakes up one thread waiting on a condition variable.
Definition: thread.c:219
static void vlc_cancel_addr_set(void *addr)
Definition: vlc_threads.h:1102
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: thread.c:236
int vlc_savecancel(void)
Disables thread cancellation.
Definition: thread.c:316
void vlc_sem_destroy(vlc_sem_t *)
Deinitializes a semaphore.
Definition: thread.c:294
unsigned vlc_GetCPUCount(void)
Count CPUs.
Definition: thread.c:421
pthread_mutex_t vlc_mutex_t
Mutex.
Definition: vlc_threads.h:278
static thread_local struct @77 state
#define vlc_tick_wait(d)
Definition: vlc_threads.h:943
vlc_tick_t value
Definition: timer.c:49
static void vlc_cleanup_lock(void *lock)
Definition: vlc_threads.h:1096
void vlc_mutex_init_recursive(vlc_mutex_t *)
Initializes a recursive mutex.
Definition: thread.c:99
vlc_mutex_t lock
Definition: rand.c:32
Definition: vlc_threads.h:1029
void vlc_timer_destroy(vlc_timer_t timer)
Destroys an initialized timer.
Definition: thread.c:998
Definition: thread.c:946
void vlc_mutex_unlock(vlc_mutex_t *)
Releases a mutex.
Definition: thread.c:134
void vlc_testcancel(void)
Issues an explicit deferred cancellation point.
Definition: thread.c:334
#define vlc_tick_sleep(d)
Definition: vlc_threads.h:942
Definition: thread.c:468
vlc_tick_t vlc_tick_now(void)
Precision monotonic clock.
Definition: thread.c:409
struct vlc_timer * vlc_timer_t
Threaded timer handle.
Definition: vlc_threads.h:343
bool vlc_addr_timedwait(void *addr, unsigned val, vlc_tick_t delay)
Waits on an address with a time-out.
Definition: thread.c:81
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition: thread.c:230
int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data, int priority)
Creates and starts a new thread.
Definition: thread.c:266
void vlc_sem_init(vlc_sem_t *, unsigned count)
Initializes a semaphore.
Definition: thread.c:288
Definition: vlc_threads.h:1140
Definition: thread.c:147
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
unsigned vlc_timer_getoverrun(vlc_timer_t)
Fetches and resets the overrun counter for a timer.
Definition: thread.c:1034
void vlc_rwlock_destroy(vlc_rwlock_t *)
Destroys an initialized unused read/write lock.
Definition: thread.c:338
void vlc_cond_broadcast(vlc_cond_t *)
Wakes up all threads waiting on a condition variable.
Definition: thread.c:225
pthread_key_t vlc_threadvar_t
Thread-local key handle.
Definition: vlc_threads.h:338
Definition: vlc_threads.h:1028
HANDLE handle
Definition: timer.c:32
void vlc_cond_init(vlc_cond_t *)
Initializes a condition variable.
Definition: thread.c:179
static void vlc_timer_schedule_asap(vlc_timer_t timer, vlc_tick_t interval)
Definition: vlc_threads.h:1002
int vlc_sem_post(vlc_sem_t *)
Increments the value of a semaphore.
Definition: thread.c:306
void vlc_rwlock_init(vlc_rwlock_t *)
Initializes a read/write lock.
Definition: thread.c:332
void vlc_cond_init_daytime(vlc_cond_t *)
Initializes a condition variable (wall clock).
Definition: thread.c:185
size_t count
Definition: core.c:402
int vlc_mutex_trylock(vlc_mutex_t *)
Tries to acquire a mutex.
Definition: thread.c:123
pthread_cond_t vlc_cond_t
Condition variable.
Definition: vlc_threads.h:290
Definition: vlc_fixups.h:409
int vlc_timer_create(vlc_timer_t *id, void(*func)(void *), void *data)
Initializes an asynchronous timer.
Definition: thread.c:978
void vlc_addr_signal(void *addr)
Wakes up one thread on an address.
Definition: thread.c:66
Definition: vlc_threads.h:1030
static void vlc_cancel_addr_clear(void *addr)
Definition: vlc_threads.h:1107
void vlc_once(vlc_once_t *restrict once, void(*cb)(void))
Executes a function one time.
#define VLC_API
Definition: fourcc_gen.c:31
Definition: vlc_threads.h:1141
sem_t vlc_sem_t
Semaphore.
Definition: vlc_threads.h:308
void vlc_rwlock_wrlock(vlc_rwlock_t *)
Acquires a read/write lock for writing.
Definition: thread.c:350
Definition: vlc_threads.h:1142
Definition: vlc_threads.h:1139
void vlc_cond_destroy(vlc_cond_t *)
Deinitializes a condition variable.
Definition: thread.c:191
int vlc_threadvar_create(vlc_threadvar_t *key, void(*destr)(void *))
Allocates a thread-specific variable.
Definition: thread.c:388
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:1011
void vlc_addr_wait(void *addr, unsigned val)
Waits on an address.
Definition: thread.c:76
#define VLC_HARD_MIN_SLEEP
Definition: vlc_threads.h:889
void vlc_mutex_lock(vlc_mutex_t *)
Acquires a mutex.
Definition: thread.c:116
pthread_rwlock_t vlc_rwlock_t
Read/write lock.
Definition: vlc_threads.h:315
void vlc_sem_wait(vlc_sem_t *)
Waits on a semaphore.
Definition: thread.c:320
void vlc_restorecancel(int state)
Restores the cancellation state.
Definition: thread.c:326
void vlc_global_mutex(unsigned, bool)
Internal handler for global mutexes.
Definition: threads.c:33
void vlc_mutex_init(vlc_mutex_t *)
Initializes a fast mutex.
Definition: thread.c:85
vlc_thread_t vlc_thread_self(void)
Thread handle.
Definition: thread.c:167
Definition: vlc_threads.h:1147
static void vlc_timer_disarm(vlc_timer_t timer)
Definition: vlc_threads.h:997
void vlc_rwlock_rdlock(vlc_rwlock_t *)
Acquires a read/write lock for reading.
Definition: thread.c:344
int poll(struct pollfd *, unsigned, int)
#define VLC_TIMER_DISARM
Definition: vlc_threads.h:973
Definition: fourcc_gen.c:51
int vlc_cond_timedwait_daytime(vlc_cond_t *, vlc_mutex_t *, time_t)
Definition: thread.c:260
void vlc_rwlock_unlock(vlc_rwlock_t *)
Releases a read/write lock.
Definition: thread.c:356
unsigned long vlc_thread_id(void)
Thread identifier.
Definition: thread.c:460
void vlc_addr_broadcast(void *addr)
Wakes up all thread on an address.
Definition: thread.c:71
void vlc_control_cancel(int cmd,...)
Internal handler for thread cancellation.
Definition: thread.c:346
Definition: vlc_threads.h:1031
void * vlc_threadvar_get(vlc_threadvar_t)
Gets the value of a thread-local variable for the calling thread.
Definition: thread.c:403
#define VLC_USED
Definition: fourcc_gen.c:32
void vlc_mutex_destroy(vlc_mutex_t *)
Deinitializes a mutex.
Definition: thread.c:110
void vlc_join(vlc_thread_t th, void **result)
Waits for a thread to complete (if needed), then destroys it.
Definition: thread.c:273
void vlc_threadvar_delete(vlc_threadvar_t *)
Deallocates a thread-specific variable.
Definition: thread.c:393