-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththread.h
44 lines (36 loc) · 1.1 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
#ifndef THREAD_H
#define THREAD_H
#if defined(__UNIX__)
# define PTHREADS
#elif defined(__WIN32__)
# define WINTHREADS
#endif
#if defined(PTHREADS)
# include <pthread.h>
typedef pthread_t thr_t;
typedef pthread_mutex_t thr_mutex_t;
typedef void * thr_exitcode_t;
typedef void *(*thr_startfunc_ptr_t)(void *);
typedef void * thr_startfunc_t;
#elif defined(WINTHREADS)
# include <windows.h>
typedef HANDLE thr_t;
typedef HANDLE thr_mutex_t;
typedef DWORD thr_exitcode_t;
typedef LPTHREAD_START_ROUTINE thr_startfunc_ptr_t;
#define thr_startfunc_t thr_exitcode_t WINAPI
#endif
int thr_create(thr_t *thread, int detached,
thr_startfunc_ptr_t startfunc, void *arg);
int thr_cancel(thr_t thread);
void thr_exit(thr_exitcode_t retval);
thr_t thr_self(void);
int thr_equal(thr_t thread1, thr_t thread2);
int thr_join(thr_t thread, thr_exitcode_t *retval);
int thr_detach(thr_t thread);
thr_mutex_t thr_mutex_create(void);
int thr_mutex_destroy(thr_mutex_t *mutex);
int thr_mutex_lock(thr_mutex_t *mutex);
int thr_mutex_trylock(thr_mutex_t *mutex);
int thr_mutex_unlock(thr_mutex_t *mutex);
#endif /* THREAD_H */