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
32/*
33 * Queued mutex
34 *
35 * A queued mutex is a type of thread-safe mutual exclusion lock that is
36 * acquired in strict FIFO order.
37 *
38 * In most cases, a regular mutex (\ref vlc_mutex_t) should be used instead.
39 * There are important differences:
40 * - A queued mutex is generally slower, especially on the fast path.
41 * - A queued mutex cannot be combined with a condition variable.
42 * Indeed, the scheduling policy of the condition variable would typically
43 * conflict with that of the queued mutex, leading to a dead lock.
44 * - The try-lock operation is not implemented.
45 */
46typedef struct {
47 atomic_uint head;
48 atomic_uint tail;
49 atomic_ulong owner;
51
52#define VLC_STATIC_QUEUEDMUTEX { 0, 0, 0 }
53
55
57
59
60/**
61 * Checks if a queued mutex is locked.
62 *
63 * This function checks if the calling thread holds a given queued mutual
64 * exclusion lock. It has no side effects and is essentially intended for
65 * run-time debugging.
66 *
67 * @note To assert that the calling thread holds a lock, the helper macro
68 * vlc_queuedmutex_assert() should be used instead of this function.
69 *
70 * @retval false the mutex is not locked by the calling thread
71 * @retval true the mutex is locked by the calling thread
72 */
74
75#define vlc_queuedmutex_assert(m) assert(vlc_queuedmutex_held(m))
76
77#endif /* !VLC_CORE_THREADS_H_ */
Definition threads.h:46
atomic_ulong owner
Definition threads.h:49
atomic_uint tail
Definition threads.h:48
atomic_uint head
Definition threads.h:47
bool vlc_queuedmutex_held(vlc_queuedmutex_t *m)
Checks if a queued mutex is locked.
Definition threads.c:450
void vlc_queuedmutex_init(vlc_queuedmutex_t *m)
Definition threads.c:443
void vlc_queuedmutex_unlock(vlc_queuedmutex_t *m)
Definition threads.c:468
void vlc_queuedmutex_lock(vlc_queuedmutex_t *m)
Definition threads.c:455
Thread primitive declarations.