]> git.sesse.net Git - vlc/blob - src/misc/threads.c
url: add one test case
[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     static_assert (VLC_MAX_MUTEX == (sizeof (locks) / sizeof (locks[0])),
47                    "Wrong number of global mutexes");
48     assert (n < (sizeof (locks) / sizeof (locks[0])));
49
50     vlc_mutex_t *lock = locks + n;
51     if (acquire)
52         vlc_mutex_lock (lock);
53     else
54         vlc_mutex_unlock (lock);
55 }