1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-20 22:02:59 +00:00
mpv/osdep/semaphore.h
wm4 34fac3bf68 osdep: hack to fix build with low quality pthreads-w32 headers
When compiling semaphore_osx.c on win32, the following error happened:

/usr/i686-w64-mingw32/include/semaphore.h:160:6: error: unknown type name 'mode_t'

This is because this system header references symbols that are not
not defined anywhere. This is clearly a bug in pthreads-w32, but has
been known and unfixed since 2012, so add a hack to fix it.

We build semaphore_osx.c this way because it saves us an extra configure
check. On win32, Linux, etc. it's empty and contains
"#include <semaphore.h>" only.

Should fix #1108.
2014-09-20 04:18:40 +02:00

60 lines
1.4 KiB
C

#ifndef MP_SEMAPHORE_H_
#define MP_SEMAPHORE_H_
#include <sys/types.h>
#include <semaphore.h>
// OSX provides non-working empty stubs, so we emulate them.
// This should be AS-safe, but cancellation issues were ignored.
// sem_getvalue() is not provided.
// sem_post() won't always correctly return an error on overflow.
// Process-shared semantics are not provided.
#ifdef __APPLE__
#define MP_SEMAPHORE_EMULATION
#include <pthread.h>
#define MP_SEM_VALUE_MAX 4096
typedef struct {
int wakeup_pipe[2];
pthread_mutex_t lock;
// protected by lock
unsigned int count;
} mp_sem_t;
int mp_sem_init(mp_sem_t *sem, int pshared, unsigned int value);
int mp_sem_wait(mp_sem_t *sem);
int mp_sem_trywait(mp_sem_t *sem);
int mp_sem_timedwait(mp_sem_t *sem, const struct timespec *abs_timeout);
int mp_sem_post(mp_sem_t *sem);
int mp_sem_destroy(mp_sem_t *sem);
#undef sem_init
#undef sem_wait
#undef sem_trywait
#undef sem_timedwait
#undef sem_post
#undef sem_getvalue
#undef sem_destroy
#undef sem_getvalue
#undef sem_t
#undef SEM_VALUE_MAX
#define sem_init mp_sem_init
#define sem_wait mp_sem_wait
#define sem_trywait mp_sem_trywait
#define sem_timedwait mp_sem_timedwait
#define sem_post mp_sem_post
#define sem_destroy mp_sem_destroy
#define sem_t mp_sem_t
#define SEM_VALUE_MAX MP_SEM_VALUE_MAX
#define sem_getvalue (void)
#endif
#endif