From 27ad0754ae84bc62548d7428fc46328a3f97b2ec Mon Sep 17 00:00:00 2001 From: surenyi Date: Thu, 16 Aug 2018 08:45:16 +0800 Subject: [PATCH] update fifo.c Signed-off-by: surenyi --- src/fifo.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/fifo.c b/src/fifo.c index f9f82b7..2c3ef86 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -2,7 +2,11 @@ #include #include #include +#ifdef _WIN32 +#include +#else #include +#endif #include "fifo.h" #define is_power_of_2(x) (((x) != 0) && (((x) & (x - 1)) == 0)) @@ -13,13 +17,24 @@ struct fifo { int size; int in; int out; +#ifdef _WIN32 + CRITICAL_SECTION lock; +#else pthread_spinlock_t lock; +#endif }; +#ifdef _WIN32 +#define SPIN_INIT(fxo) InitializeCriticalSection(&fxo->lock) +#define SPIN_RELEASE(fxo) DeleteCriticalSection(&fxo->lock) +#define SPIN_LOCK(fxo) EnterCriticalSection(&fxo->lock) +#define SPIN_UNLOCK(fxo) LeaveCriticalSection(&fxo->lock) +#else #define SPIN_INIT(fxo) pthread_spin_init(&fxo->lock, PTHREAD_PROCESS_PRIVATE) #define SPIN_RELEASE(fxo) pthread_spin_destroy(&fxo->lock) #define SPIN_LOCK(fxo) pthread_spin_lock(&fxo->lock) #define SPIN_UNLOCK(fxo) pthread_spin_unlock(&fxo->lock) +#endif static unsigned int roundup_pow_of_two(unsigned int x) {