2017-04-15 14:20:00 +00:00
|
|
|
/* Copyright (C) 2017 the mpv developers
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2015-01-01 14:10:42 +00:00
|
|
|
#ifndef MP_WRAP_SEMAPHORE_H_
|
|
|
|
#define MP_WRAP_SEMAPHORE_H_
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
// See pthread.h for rationale.
|
|
|
|
#define sem_init m_sem_init
|
|
|
|
#define sem_destroy m_sem_destroy
|
|
|
|
#define sem_wait m_sem_wait
|
|
|
|
#define sem_trywait m_sem_trywait
|
|
|
|
#define sem_timedwait m_sem_timedwait
|
|
|
|
#define sem_post m_sem_post
|
|
|
|
|
|
|
|
#define SEM_VALUE_MAX 100
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_cond_t wakeup;
|
|
|
|
unsigned int value;
|
|
|
|
} sem_t;
|
|
|
|
|
|
|
|
int sem_init(sem_t *sem, int pshared, unsigned int value);
|
|
|
|
int sem_destroy(sem_t *sem);
|
|
|
|
int sem_wait(sem_t *sem);
|
|
|
|
int sem_trywait(sem_t *sem);
|
|
|
|
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
|
|
|
|
int sem_post(sem_t *sem);
|
|
|
|
|
|
|
|
#endif
|