a lot of stuff tbh
This commit is contained in:
parent
d80773bb00
commit
8ddd9186b8
42 changed files with 6463 additions and 1593 deletions
67
cthreads.h
67
cthreads.h
|
|
@ -1,67 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// == THREAD ===========================================
|
||||
|
||||
typedef uintptr_t cthread_t;
|
||||
|
||||
typedef int (*cthread_func_t)(void *);
|
||||
|
||||
cthread_t thrCreate(cthread_func_t func, void *arg);
|
||||
bool thrValid(cthread_t ctx);
|
||||
bool thrDetach(cthread_t ctx);
|
||||
|
||||
cthread_t thrCurrent(void);
|
||||
int thrCurrentId(void);
|
||||
int thrGetId(cthread_t ctx);
|
||||
|
||||
void thrExit(int code);
|
||||
bool thrJoin(cthread_t ctx, int *code);
|
||||
|
||||
// == MUTEX ============================================
|
||||
|
||||
typedef uintptr_t cmutex_t;
|
||||
|
||||
cmutex_t mtxInit(void);
|
||||
void mtxDestroy(cmutex_t ctx);
|
||||
|
||||
bool mtxValid(cmutex_t ctx);
|
||||
|
||||
bool mtxLock(cmutex_t ctx);
|
||||
bool mtxTryLock(cmutex_t ctx);
|
||||
bool mtxUnlock(cmutex_t ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
// small c++ class to make mutexes easier to use
|
||||
struct lock_t {
|
||||
inline lock_t(cmutex_t mutex)
|
||||
: mutex(mutex) {
|
||||
if (mtxValid(mutex)) {
|
||||
mtxLock(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
inline ~lock_t() {
|
||||
unlock();
|
||||
}
|
||||
|
||||
inline void unlock() {
|
||||
if (mtxValid(mutex)) {
|
||||
mtxUnlock(mutex);
|
||||
}
|
||||
mutex = 0;
|
||||
}
|
||||
|
||||
cmutex_t mutex;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue