22 #ifndef AVUTIL_THREAD_H
23 #define AVUTIL_THREAD_H
27 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
34 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
38 #define ASSERT_PTHREAD_NORET(func, ...) do { \
39 int ret = func(__VA_ARGS__); \
41 av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func) \
42 " failed with error: %s\n", av_err2str(AVERROR(ret))); \
47 #define ASSERT_PTHREAD(func, ...) do { \
48 ASSERT_PTHREAD_NORET(func, __VA_ARGS__); \
52 static inline int strict_pthread_join(
pthread_t thread,
void **value_ptr)
63 ASSERT_PTHREAD_NORET(pthread_mutexattr_init, &local_attr);
64 ASSERT_PTHREAD_NORET(pthread_mutexattr_settype, &local_attr, PTHREAD_MUTEX_ERRORCHECK);
66 ASSERT_PTHREAD_NORET(pthread_mutexattr_destroy, &local_attr);
91 static inline int strict_pthread_cond_destroy(
pthread_cond_t *cond)
101 static inline int strict_pthread_cond_broadcast(
pthread_cond_t *cond)
111 static inline int strict_pthread_once(
pthread_once_t *once_control,
void (*init_routine)(
void))
113 ASSERT_PTHREAD(
pthread_once, once_control, init_routine);
116 #define pthread_join strict_pthread_join
117 #define pthread_mutex_init strict_pthread_mutex_init
118 #define pthread_mutex_destroy strict_pthread_mutex_destroy
119 #define pthread_mutex_lock strict_pthread_mutex_lock
120 #define pthread_mutex_unlock strict_pthread_mutex_unlock
121 #define pthread_cond_init strict_pthread_cond_init
122 #define pthread_cond_destroy strict_pthread_cond_destroy
123 #define pthread_cond_signal strict_pthread_cond_signal
124 #define pthread_cond_broadcast strict_pthread_cond_broadcast
125 #define pthread_cond_wait strict_pthread_cond_wait
126 #define pthread_once strict_pthread_once
129 #elif HAVE_OS2THREADS
135 #define AVMutex pthread_mutex_t
137 #define ff_mutex_init pthread_mutex_init
138 #define ff_mutex_lock pthread_mutex_lock
139 #define ff_mutex_unlock pthread_mutex_unlock
140 #define ff_mutex_destroy pthread_mutex_destroy
142 #define AVOnce pthread_once_t
143 #define AV_ONCE_INIT PTHREAD_ONCE_INIT
145 #define ff_thread_once(control, routine) pthread_once(control, routine)
149 #define USE_ATOMICS 1
153 #define ff_mutex_init(mutex, attr) (0)
154 #define ff_mutex_lock(mutex) (0)
155 #define ff_mutex_unlock(mutex) (0)
156 #define ff_mutex_destroy(mutex) (0)
159 #define AV_ONCE_INIT 0
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
os2threads to pthreads wrapper
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static pthread_mutex_t * mutex
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static int ff_thread_once(char *control, void(*routine)(void))
w32threads to pthreads wrapper
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))