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