try to accomodate apple
This commit is contained in:
parent
3ad333ea50
commit
4200c23f6e
7
io.h
7
io.h
@ -209,13 +209,16 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb
|
||||
unsigned int io_debugstring(int64 s,char* buf,unsigned int bufsize);
|
||||
|
||||
#ifdef __MINGW32__
|
||||
// https://github.com/lhmouse/mcfgthread
|
||||
#include <mcfgthread/c11.h>
|
||||
#elif defined(__dietlibc__)
|
||||
#include <threads.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#ifndef __APPLE__
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum { SLOTS=128 };
|
||||
typedef struct iomux {
|
||||
@ -228,6 +231,9 @@ typedef struct iomux {
|
||||
#if defined(__MINGW32__) || defined(__dietlibc__)
|
||||
mtx_t mtx;
|
||||
cnd_t sem;
|
||||
#elif defined(__APPLE__)
|
||||
pthread_mutex_t mtx;
|
||||
pthread_cond_t sem;
|
||||
#else
|
||||
sem_t sem;
|
||||
#endif
|
||||
@ -253,6 +259,7 @@ int iom_add(iomux_t* c,int64 s,unsigned int events);
|
||||
int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout);
|
||||
|
||||
/* Call this to terminate all threads waiting in iom_wait */
|
||||
/* Returns 0 on success, -1 on failure */
|
||||
int iom_abort(iomux_t* c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -3,7 +3,9 @@
|
||||
int iom_abort(iomux_t* c) {
|
||||
c->working=-2;
|
||||
#ifdef __dietlibc__
|
||||
return cnd_broadcast(&c->sem);
|
||||
return cnd_broadcast(&c->sem) == thrd_success ? 0 : -1;
|
||||
#elif defined(__APPLE__)
|
||||
return pthread_cond_broadcast(&c->sem) == 0 ? 0 : -1;
|
||||
#else
|
||||
return sem_post(&c->sem);
|
||||
#endif
|
||||
|
@ -33,6 +33,9 @@ int iom_init(iomux_t* c) {
|
||||
#ifdef __dietlibc__
|
||||
mtx_init(&c->mtx, mtx_timed);
|
||||
cnd_init(&c->sem);
|
||||
#elif defined(__APPLE__)
|
||||
pthread_mutex_init(&c->mtx, 0);
|
||||
pthread_cond_init(&c->sem, 0);
|
||||
#else
|
||||
sem_init(&c->sem, 0, 1);
|
||||
#endif
|
||||
|
@ -79,6 +79,8 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
||||
// not transient, then they will also get an error and wake the
|
||||
// next up
|
||||
cnd_signal(&c->sem);
|
||||
#elif defined(__APPLE__)
|
||||
pthread_cond_signal(&c->sem);
|
||||
#else
|
||||
sem_post(&c->sem);
|
||||
#endif
|
||||
@ -117,6 +119,8 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
||||
#ifdef __dietlibc__
|
||||
// no dietlibc for kqueue based systems yet
|
||||
cnd_broadcast(&c->sem);
|
||||
#elif defined(__APPLE__)
|
||||
pthread_cond_broadcast(&c->sem);
|
||||
#else
|
||||
sem_post(&c->sem);
|
||||
#endif
|
||||
@ -155,6 +159,11 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
||||
cnd_signal(&c->sem);
|
||||
else
|
||||
cnd_broadcast(&c->sem);
|
||||
#elif defined(__APPLE__)
|
||||
if (c->h == (c->l + 1) % SLOTS)
|
||||
pthread_cond_signal(&c->sem);
|
||||
else
|
||||
pthread_cond_broadcast(&c->sem);
|
||||
#else
|
||||
sem_post(&c->sem);
|
||||
#endif
|
||||
@ -166,6 +175,8 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
||||
ts.tv_nsec = (timeout % 1000) * 1000000;
|
||||
#ifdef __dietlibc__
|
||||
r=cnd_timedwait(&c->sem,&c->mtx,&ts);
|
||||
#elif defined(__APPLE__)
|
||||
r=pthread_cond_timedwait(&c->sem,&c->mtx,&ts);
|
||||
#else
|
||||
r=sem_timedwait(&c->sem,&ts);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user