57 lines
1.9 KiB
C
57 lines
1.9 KiB
C
|
|
#ifndef CGE_THREAD_H
|
||
|
|
#define CGE_THREAD_H
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
enum CgeThreadCode {
|
||
|
|
CGE_THREAD_EOK,
|
||
|
|
CGE_THREAD_EUNKNOWN,
|
||
|
|
CGE_THREAD_EINVAL,
|
||
|
|
CGE_THREAD_EOOM,
|
||
|
|
CGE_THREAD_ETIMEDOUT,
|
||
|
|
CGE_THREAD_EBUSY,
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct CgeThread CgeThread;
|
||
|
|
typedef struct CgeMutex CgeMutex;
|
||
|
|
typedef struct CgeSemaphore CgeSemaphore;
|
||
|
|
typedef struct CgeCondition CgeCondition;
|
||
|
|
typedef struct CgeTss CgeTss;
|
||
|
|
typedef int (*CgeThreadCallback)(void *);
|
||
|
|
typedef void (*CgeTssCallback)(void *);
|
||
|
|
|
||
|
|
CgeThread *CgeThreadNew(size_t stack, CgeThreadCallback callback, void *data,
|
||
|
|
int *result);
|
||
|
|
int CgeThreadJoin(CgeThread *thread, int *result);
|
||
|
|
int CgeThreadDetach(CgeThread *thread, int *result);
|
||
|
|
void CgeThreadSleep(uint32_t timeout);
|
||
|
|
|
||
|
|
CgeMutex *CgeMutexNew(int *result);
|
||
|
|
void CgeMutexFree(CgeMutex *mutex);
|
||
|
|
int CgeMutexLock(CgeMutex *mutex, int *result);
|
||
|
|
int CgeMutexUnlock(CgeMutex *mutex, int *result);
|
||
|
|
int CgeMutexTryLock(CgeMutex *mutex, int *result);
|
||
|
|
|
||
|
|
CgeSemaphore *CgeSemaphoreNew(int value, int *result);
|
||
|
|
void CgeSemaphoreFree(CgeSemaphore *semaphore);
|
||
|
|
int CgeSemaphorePost(CgeSemaphore *semaphore, int *result);
|
||
|
|
int CgeSemaphoreWait(CgeSemaphore *semaphore, int *result);
|
||
|
|
int CgeSemaphoreTryWait(CgeSemaphore *semaphore, int *result);
|
||
|
|
int CgeSemaphoreWaitFor(CgeSemaphore *semaphore, uint32_t timeout, int *result);
|
||
|
|
|
||
|
|
CgeCondition *CgeConditionNew(int *result);
|
||
|
|
void CgeConditionFree(CgeCondition *condition);
|
||
|
|
int CgeConditionWait(CgeCondition *condition, CgeMutex *mutex, int *result);
|
||
|
|
int CgeConditionWaitFor(CgeCondition *condition, CgeMutex *mutex,
|
||
|
|
uint32_t timeout, int *result);
|
||
|
|
int CgeConditionSignal(CgeCondition *condition, int *result);
|
||
|
|
int CgeConditionBroadcast(CgeCondition *condition, int *result);
|
||
|
|
|
||
|
|
CgeTss *CgeTssNew(CgeTssCallback callback, int *result);
|
||
|
|
void CgeTssFree(CgeTss *tss);
|
||
|
|
void *CgeTssRead(CgeTss *tss);
|
||
|
|
void CgeTssWrite(CgeTss *tss, void *value);
|
||
|
|
|
||
|
|
#endif /* CGE_THREAD_H */
|