some stuff

This commit is contained in:
bumbread 2022-06-28 13:08:03 +11:00
parent be2c9d132e
commit 14c3e8b758
1 changed files with 44 additions and 41 deletions

View File

@ -6,19 +6,15 @@
#define thread_local _Thread_local #define thread_local _Thread_local
#define ONCE_FLAG_INIT 1 #define ONCE_FLAG_INIT 1
#define TSS_DTOR_ITERATIONS 32 #define TSS_DTOR_ITERATIONS 32
#if defined(_WIN32)
typedef struct cnd_t { typedef struct cnd_t {
int idk_yet; int idk_yet;
} cnd_t; } cnd_t;
typedef struct thrd_t { typedef struct thrd_t {
#if defined(_WIN32)
void* handle; void* handle;
#else
#error "C11 thread has not been implemented on this platform"
#endif
} thrd_t; } thrd_t;
typedef struct tss_t { typedef struct tss_t {
@ -26,28 +22,25 @@ typedef struct tss_t {
} tss_t; } tss_t;
typedef struct mtx_t { typedef struct mtx_t {
#if defined(_WIN32)
int type; int type;
// Done to handle recursive mutexes // Done to handle recursive mutexes
unsigned long recursion; unsigned long recursion;
unsigned long owner; unsigned long owner;
atomic_int counter; atomic_int counter;
void* semaphore; void* semaphore;
#else
#error "C11 mutex has not been implemented on this platform"
#endif
} mtx_t; } mtx_t;
#else
#error "Not implemented"
#endif
typedef void(*tss_dtor_t) (void*); typedef void(*tss_dtor_t) (void*);
typedef int (*thrd_start_t)(void*); typedef int (*thrd_start_t)(void*);
typedef int once_flag; // TODO: change this maybe?
// TODO: change this maybe?
typedef int once_flag;
enum { enum {
mtx_plain = 1, mtx_plain = 0,
mtx_recursive = 2, mtx_recursive = 1,
mtx_timed = 4 mtx_timed = 2,
}; };
enum { enum {
@ -60,28 +53,38 @@ enum {
void call_once(once_flag *flag, void (*func)(void)); void call_once(once_flag *flag, void (*func)(void));
int cnd_init (cnd_t *cond);
int cnd_broadcast(cnd_t *cond); int cnd_broadcast(cnd_t *cond);
void cnd_destroy (cnd_t *cond); void cnd_destroy (cnd_t *cond);
int cnd_init(cnd_t *cond);
int cnd_signal (cnd_t *cond); int cnd_signal (cnd_t *cond);
int cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx, const struct timespec *restrict ts);
int cnd_wait (cnd_t *cond, mtx_t *mtx); int cnd_wait (cnd_t *cond, mtx_t *mtx);
int cnd_timedwait(
cnd_t *restrict cond,
mtx_t *restrict mtx,
const struct timespec *restrict ts
);
void mtx_destroy (mtx_t *mtx); void mtx_destroy (mtx_t *mtx);
int mtx_init (mtx_t *mtx, int type); int mtx_init (mtx_t *mtx, int type);
int mtx_lock(mtx_t *mtx);
int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts);
int mtx_trylock(mtx_t *mtx);
int mtx_unlock (mtx_t *mtx); int mtx_unlock (mtx_t *mtx);
int mtx_trylock (mtx_t *mtx);
int mtx_lock (mtx_t *mtx);
int mtx_timedlock(
mtx_t *restrict mtx,
const struct timespec *restrict ts
);
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
thrd_t thrd_current(void); thrd_t thrd_current(void);
int thrd_create (thrd_t *thr, thrd_start_t func, void *arg);
int thrd_detach (thrd_t thr); int thrd_detach (thrd_t thr);
int thrd_equal (thrd_t thr0, thrd_t thr1); int thrd_equal (thrd_t thr0, thrd_t thr1);
_Noreturn void thrd_exit(int res);
int thrd_join (thrd_t thr, int *res); int thrd_join (thrd_t thr, int *res);
int thrd_sleep(const struct timespec *duration, struct timespec *remaining);
void thrd_yield (void); void thrd_yield (void);
_Noreturn void thrd_exit(int res);
int thrd_sleep(
const struct timespec *duration,
struct timespec *remaining
);
int tss_create(tss_t *key, tss_dtor_t dtor); int tss_create(tss_t *key, tss_dtor_t dtor);
void tss_delete(tss_t key); void tss_delete(tss_t key);