]> git.sesse.net Git - vlc/blob - src/misc/threads.c
LGPL
[vlc] / src / misc / threads.c
1 /*****************************************************************************
2  * threads.c : threads implementation for the VideoLAN client
3  *****************************************************************************
4  * Copyright (C) 1999-2008 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@netcourrier.com>
10  *          Clément Sténac
11  *          Rémi Denis-Courmont
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 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <assert.h>
34
35 /*** Global locks ***/
36
37 void vlc_global_mutex (unsigned n, bool acquire)
38 {
39     static vlc_mutex_t locks[] = {
40         VLC_STATIC_MUTEX,
41         VLC_STATIC_MUTEX,
42         VLC_STATIC_MUTEX,
43         VLC_STATIC_MUTEX,
44         VLC_STATIC_MUTEX,
45     };
46     assert (n < (sizeof (locks) / sizeof (locks[0])));
47     vlc_mutex_t *lock = locks + n;
48
49     if (acquire)
50         vlc_mutex_lock (lock);
51     else
52         vlc_mutex_unlock (lock);
53
54     /* Compile-time assertion ;-) */
55     char enough_locks[(sizeof (locks) / sizeof (locks[0])) - VLC_MAX_MUTEX];
56     (void) enough_locks;
57 }