-
Notifications
You must be signed in to change notification settings - Fork 28
/
sema.h
27 lines (22 loc) · 781 Bytes
/
sema.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef _JACK_CAPTURE_SEMA_H
#define _JACK_CAPTURE_SEMA_H
#include <errno.h>
#ifdef __APPLE__
#include <mach/mach.h>
#include <sys/sysinfo.h>
#else
#include <semaphore.h>
#endif
#include "jack_capture.h"
#ifdef __APPLE__
#define SEM_TYPE_T semaphore_t
#define SEM_INIT(Sem) semaphore_create(mach_task_self(), &Sem, SYNC_POLICY_FIFO, 0)
#define SEM_SIGNAL(Sem) semaphore_signal(Sem)
#define SEM_WAIT(Sem) {kern_return_t ret;while((ret=semaphore_wait(Sem))!=KERN_SUCCESS) print_message("Warning: semaphore_wait failed: %d",ret);}
#else
#define SEM_TYPE_T sem_t
#define SEM_INIT(Sem) sem_init(&Sem,0,0)
#define SEM_SIGNAL(Sem) sem_post(&Sem)
#define SEM_WAIT(Sem) while(sem_wait(&Sem)==-1) print_message("Warning: sem_wait failed: %s",strerror(errno));
#endif
#endif