Libav
thread.h
Go to the documentation of this file.
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
32 #include "compat/w32pthreads.h"
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 
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 
47 #else
48 
49 #define AVMutex char
50 
51 #define ff_mutex_init(mutex, attr) (0)
52 #define ff_mutex_lock(mutex) (0)
53 #define ff_mutex_unlock(mutex) (0)
54 #define ff_mutex_destroy(mutex) (0)
55 
56 #define AVOnce char
57 #define AV_ONCE_INIT 0
58 
59 static 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 
68 #endif
69 
70 #endif /* AVUTIL_THREAD_H */
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:59
w32threads to pthreads wrapper