37 lines
702 B
C
37 lines
702 B
C
#ifndef BLUELIB_CORE_THREAD_H_
|
|
#define BLUELIB_CORE_THREAD_H_
|
|
|
|
#include <blue/core/bitop.h>
|
|
#include <blue/core/misc.h>
|
|
#include <stdbool.h>
|
|
|
|
#if defined(__APPLE__) || defined(__linux__)
|
|
#include <pthread.h>
|
|
|
|
#define B_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
|
|
|
|
typedef pthread_mutex_t b_mutex;
|
|
#else
|
|
#error Unsupported compiler/system
|
|
#endif
|
|
|
|
#define B_ONCE_INIT ((b_once)0)
|
|
|
|
typedef struct b_thread b_thread;
|
|
|
|
typedef int b_once;
|
|
|
|
static inline bool b_init_once(b_once *once)
|
|
{
|
|
int x = 0;
|
|
return b_cmpxchg(once, &x, 1);
|
|
}
|
|
|
|
BLUE_API b_thread *b_thread_self(void);
|
|
|
|
BLUE_API bool b_mutex_lock(b_mutex *mut);
|
|
BLUE_API bool b_mutex_trylock(b_mutex *mut);
|
|
BLUE_API bool b_mutex_unlock(b_mutex *mut);
|
|
|
|
#endif
|