-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy paththread.h
44 lines (37 loc) · 1.02 KB
/
thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// thread.h
// Thin interface over the Windows Threads API and pthread.
#ifndef __THREAD_H__
#define __THREAD_H__
// Basic types: ThreadHandle, ThreadId, Mutex, Event
#ifdef WIN32
#include <windows.h>
typedef HANDLE ThreadHandle;
typedef DWORD ThreadId;
typedef CRITICAL_SECTION Mutex;
typedef HANDLE Event;
#else
#include <pthread.h>
typedef pthread_t ThreadHandle;
typedef pthread_t ThreadId;
typedef pthread_mutex_t Mutex;
struct Event
{
pthread_mutex_t mutex;
pthread_cond_t cond;
bool triggered;
};
#endif
typedef void* (*ThreadProc)(void* arg);
ThreadHandle threadCreate(ThreadProc proc, void* arg);
ThreadId threadGetCurrentId();
void threadJoin(ThreadHandle id);
void mutexCreate(Mutex* mutex);
void mutexDestroy(Mutex* mutex);
void mutexLock(Mutex* mutex);
void mutexUnlock(Mutex* mutex);
void eventCreate(Event* event);
void eventDestroy(Event* event);
void eventTrigger(Event* event);
void eventReset(Event* event);
void eventWait(Event* event);
#endif // __THREAD_H__