VLC 4.0.0-dev
Loading...
Searching...
No Matches
threads.h
Go to the documentation of this file.
1/*****************************************************************************
2 * threads.h : core internal threads implementation for the VideoLAN client
3 *****************************************************************************
4 * Copyright (C) 1999, 2002 VLC authors and VideoLAN
5 * Copyright © 2007-2016 Rémi Denis-Courmont
6 *
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@via.ecp.fr>
9 * Gildas Bazin <gbazin@netcourrier.com>
10 * Christophe Massiot <massiot@via.ecp.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
26
27#ifndef VLC_CORE_THREADS_H_
28#define VLC_CORE_THREADS_H_
29
30#include <vlc_threads.h>
31
33
34/*
35 * Queued mutex
36 *
37 * A queued mutex is a type of thread-safe mutual exclusion lock that is
38 * acquired in strict FIFO order.
39 *
40 * In most cases, a regular mutex (\ref vlc_mutex_t) should be used instead.
41 * There are important differences:
42 * - A queued mutex is generally slower, especially on the fast path.
43 * - A queued mutex cannot be combined with a condition variable.
44 * Indeed, the scheduling policy of the condition variable would typically
45 * conflict with that of the queued mutex, leading to a dead lock.
46 * - The try-lock operation is not implemented.
47 */
48typedef struct {
49 atomic_uint head;
50 atomic_uint tail;
51 atomic_ulong owner;
53
54#define VLC_STATIC_QUEUEDMUTEX { 0, 0, 0 }
55
57
59
61
62/**
63 * Checks if a queued mutex is locked.
64 *
65 * This function checks if the calling thread holds a given queued mutual
66 * exclusion lock. It has no side effects and is essentially intended for
67 * run-time debugging.
68 *
69 * @note To assert that the calling thread holds a lock, the helper macro
70 * vlc_queuedmutex_assert() should be used instead of this function.
71 *
72 * @retval false the mutex is not locked by the calling thread
73 * @retval true the mutex is locked by the calling thread
74 */
76
77#define vlc_queuedmutex_assert(m) assert(vlc_queuedmutex_held(m))
78
79#endif /* !VLC_CORE_THREADS_H_ */
Condition variable.
Definition vlc_threads.h:270
Mutex.
Definition vlc_threads.h:143
Definition threads.h:48
atomic_ulong owner
Definition threads.h:51
atomic_uint tail
Definition threads.h:50
atomic_uint head
Definition threads.h:49
bool vlc_queuedmutex_held(vlc_queuedmutex_t *m)
Checks if a queued mutex is locked.
Definition threads.c:463
void vlc_queuedmutex_init(vlc_queuedmutex_t *m)
Definition threads.c:456
void vlc_queuedmutex_unlock(vlc_queuedmutex_t *m)
Definition threads.c:481
int vlc_cond_timedwait_daytime(vlc_cond_t *, vlc_mutex_t *, time_t)
Definition threads.c:308
void vlc_queuedmutex_lock(vlc_queuedmutex_t *m)
Definition threads.c:468
Thread primitive declarations.