|
@ -2,7 +2,11 @@ |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
#include <stdint.h> |
|
|
#include <stdint.h> |
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
#include <windows.h> |
|
|
|
|
|
#else |
|
|
#include <pthread.h> |
|
|
#include <pthread.h> |
|
|
|
|
|
#endif |
|
|
#include "fifo.h" |
|
|
#include "fifo.h" |
|
|
|
|
|
|
|
|
#define is_power_of_2(x) (((x) != 0) && (((x) & (x - 1)) == 0)) |
|
|
#define is_power_of_2(x) (((x) != 0) && (((x) & (x - 1)) == 0)) |
|
@ -13,13 +17,24 @@ struct fifo { |
|
|
int size; |
|
|
int size; |
|
|
int in; |
|
|
int in; |
|
|
int out; |
|
|
int out; |
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
CRITICAL_SECTION lock; |
|
|
|
|
|
#else |
|
|
pthread_spinlock_t lock; |
|
|
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_INIT(fxo) pthread_spin_init(&fxo->lock, PTHREAD_PROCESS_PRIVATE) |
|
|
#define SPIN_RELEASE(fxo) pthread_spin_destroy(&fxo->lock) |
|
|
#define SPIN_RELEASE(fxo) pthread_spin_destroy(&fxo->lock) |
|
|
#define SPIN_LOCK(fxo) pthread_spin_lock(&fxo->lock) |
|
|
#define SPIN_LOCK(fxo) pthread_spin_lock(&fxo->lock) |
|
|
#define SPIN_UNLOCK(fxo) pthread_spin_unlock(&fxo->lock) |
|
|
#define SPIN_UNLOCK(fxo) pthread_spin_unlock(&fxo->lock) |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
static unsigned int roundup_pow_of_two(unsigned int x) |
|
|
static unsigned int roundup_pow_of_two(unsigned int x) |
|
|
{ |
|
|
{ |
|
|