-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy paththread_helper.h
30 lines (26 loc) · 1.34 KB
/
thread_helper.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
#ifndef _thread_helper_h
#define _thread_helper_h
#ifdef FreeBSD
#include <pthread_np.h>
#endif
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#define handle_error_en(en, msg) \
do { \
errno = en; \
perror(msg); \
exit(EXIT_FAILURE); \
} while (0)
#define Pthread_create(thread, attr, start_routine, arg) \
assert(pthread_create(thread, attr, start_routine, arg) == 0)
#define Pthread_join(thread, value_ptr) \
assert(pthread_join(thread, value_ptr) == 0)
#define Pthread_cancel(thread) assert(pthread_cancel(thread) == 0)
#define Pthread_mutex_init(m, attr) assert(pthread_mutex_init(m, attr) == 0)
#define Pthread_mutex_lock(m) assert(pthread_mutex_lock(m) == 0)
#define Pthread_mutex_unlock(m) assert(pthread_mutex_unlock(m) == 0)
#define Pthread_mutex_destroy(m) assert(pthread_mutex_destroy(m) == 0)
#define Pthread_setaffinity_np(thread, cpusetsize, cpuset) \
assert(pthread_setaffinity_np(thread, cpusetsize, cpuset) == 0)
#endif // _thread_helper_h