thread: Define ff_mutex_* macros as stub functions when threads are disabled
[libav.git] / libavutil / thread.h
CommitLineData
2443e522
AK
1/*
2 * This file is part of Libav.
3 *
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19// This header should only be used to simplify code where
20// threading is optional, not as a generic threading abstraction.
21
22#ifndef AVUTIL_THREAD_H
23#define AVUTIL_THREAD_H
24
25#include "config.h"
26
27#if HAVE_PTHREADS || HAVE_W32THREADS
28
29#if HAVE_PTHREADS
30#include <pthread.h>
31#else
e10e6651 32#include "compat/w32pthreads.h"
2443e522
AK
33#endif
34
35#define AVMutex pthread_mutex_t
36
37#define ff_mutex_init pthread_mutex_init
38#define ff_mutex_lock pthread_mutex_lock
39#define ff_mutex_unlock pthread_mutex_unlock
40#define ff_mutex_destroy pthread_mutex_destroy
41
c53e796f
LB
42#define AVOnce pthread_once_t
43#define AV_ONCE_INIT PTHREAD_ONCE_INIT
44
45#define ff_thread_once(control, routine) pthread_once(control, routine)
46
2443e522
AK
47#else
48
49#define AVMutex char
50
193b0918
DB
51static inline int ff_mutex_init(AVMutex *mutex, const void *attr){ return 0; }
52static inline int ff_mutex_lock(AVMutex *mutex){ return 0; }
53static inline int ff_mutex_unlock(AVMutex *mutex){ return 0; }
54static inline int ff_mutex_destroy(AVMutex *mutex){ return 0; }
2443e522 55
c53e796f
LB
56#define AVOnce char
57#define AV_ONCE_INIT 0
58
59static inline int ff_thread_once(char *control, void (*routine)(void))
60{
61 if (!*control) {
62 routine();
63 *control = 1;
64 }
65 return 0;
66}
67
2443e522
AK
68#endif
69
70#endif /* AVUTIL_THREAD_H */