22#ifndef AVUTIL_THREAD_H
23#define AVUTIL_THREAD_H
29#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_NP_H
30#include <pthread_np.h>
35#if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
40#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
47#define ASSERT_PTHREAD_ABORT(func, ret) do { \
48 char errbuf[AV_ERROR_MAX_STRING_SIZE] = ""; \
49 av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func) \
50 " failed with error: %s\n", \
51 av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, \
56#define ASSERT_PTHREAD_NORET(func, ...) do { \
57 int ret = func(__VA_ARGS__); \
59 ASSERT_PTHREAD_ABORT(func, ret); \
62#define ASSERT_PTHREAD(func, ...) do { \
63 ASSERT_PTHREAD_NORET(func, __VA_ARGS__); \
67static inline int strict_pthread_join(
pthread_t thread,
void **value_ptr)
78 ASSERT_PTHREAD_NORET(pthread_mutexattr_init, &local_attr);
79 ASSERT_PTHREAD_NORET(pthread_mutexattr_settype, &local_attr, PTHREAD_MUTEX_ERRORCHECK);
81 ASSERT_PTHREAD_NORET(pthread_mutexattr_destroy, &local_attr);
127 const struct timespec *abstime)
130 if (ret && ret != ETIMEDOUT)
135static inline int strict_pthread_once(
pthread_once_t *once_control,
void (*init_routine)(
void))
137 ASSERT_PTHREAD(
pthread_once, once_control, init_routine);
140#define pthread_join strict_pthread_join
141#define pthread_mutex_init strict_pthread_mutex_init
142#define pthread_mutex_destroy strict_pthread_mutex_destroy
143#define pthread_mutex_lock strict_pthread_mutex_lock
144#define pthread_mutex_unlock strict_pthread_mutex_unlock
145#define pthread_cond_init strict_pthread_cond_init
146#define pthread_cond_destroy strict_pthread_cond_destroy
147#define pthread_cond_signal strict_pthread_cond_signal
148#define pthread_cond_broadcast strict_pthread_cond_broadcast
149#define pthread_cond_wait strict_pthread_cond_wait
150#define pthread_cond_timedwait strict_pthread_cond_timedwait
151#define pthread_once strict_pthread_once
160#define AVMutex pthread_mutex_t
161#define AV_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
163#define ff_mutex_init pthread_mutex_init
164#define ff_mutex_lock pthread_mutex_lock
165#define ff_mutex_unlock pthread_mutex_unlock
166#define ff_mutex_destroy pthread_mutex_destroy
168#define AVCond pthread_cond_t
170#define ff_cond_init pthread_cond_init
171#define ff_cond_destroy pthread_cond_destroy
172#define ff_cond_signal pthread_cond_signal
173#define ff_cond_broadcast pthread_cond_broadcast
174#define ff_cond_wait pthread_cond_wait
175#define ff_cond_timedwait pthread_cond_timedwait
177#define AVOnce pthread_once_t
178#define AV_ONCE_INIT PTHREAD_ONCE_INIT
180#define ff_thread_once(control, routine) pthread_once(control, routine)
185#define AV_MUTEX_INITIALIZER 0
200 const void *abstime){
return 0; }
203#define AV_ONCE_INIT 0
222#elif HAVE_PTHREAD_SETNAME_NP
223#if defined(__APPLE__)
225#elif defined(__NetBSD__)
226 ret =
AVERROR(pthread_setname_np(pthread_self(),
"%s",
name));
228 ret =
AVERROR(pthread_setname_np(pthread_self(),
name));
230#elif HAVE_PTHREAD_SET_NAME_NP
231 pthread_set_name_np(pthread_self(),
name);
static int ff_cond_wait(AVCond *cond, AVMutex *mutex)
static int ff_mutex_unlock(AVMutex *mutex)
static int ff_cond_destroy(AVCond *cond)
static int ff_mutex_lock(AVMutex *mutex)
static int ff_thread_once(char *control, void(*routine)(void))
static int ff_mutex_destroy(AVMutex *mutex)
static int ff_cond_init(AVCond *cond, const void *attr)
static int ff_cond_timedwait(AVCond *cond, AVMutex *mutex, const void *abstime)
static int ff_thread_setname(const char *name)
static int ff_cond_signal(AVCond *cond)
static int ff_cond_broadcast(AVCond *cond)
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Utility Preprocessor macros.
os2threads to pthreads wrapper
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
static av_always_inline int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static av_always_inline int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
int(* cond)(enum AVPixelFormat pix_fmt)
w32threads to pthreads wrapper
static int win32_thread_setname(const char *name)