forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrappthread.c
188 lines (155 loc) · 3.06 KB
/
wrappthread.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* pthreads wrapper functions.
*/
#include "unp.h"
#include "unpthread.h"
void
Pthread_create(pthread_t *tid, const pthread_attr_t *attr,
void * (*func)(void *), void *arg)
{
int n;
if ( (n = pthread_create(tid, attr, func, arg)) == 0)
return;
errno = n;
err_sys("pthread_create error");
}
void
Pthread_join(pthread_t tid, void **status)
{
int n;
if ( (n = pthread_join(tid, status)) == 0)
return;
errno = n;
err_sys("pthread_join error");
}
void
Pthread_detach(pthread_t tid)
{
int n;
if ( (n = pthread_detach(tid)) == 0)
return;
errno = n;
err_sys("pthread_detach error");
}
void
Pthread_kill(pthread_t tid, int signo)
{
int n;
if ( (n = pthread_kill(tid, signo)) == 0)
return;
errno = n;
err_sys("pthread_kill error");
}
void
Pthread_mutexattr_init(pthread_mutexattr_t *attr)
{
int n;
if ( (n = pthread_mutexattr_init(attr)) == 0)
return;
errno = n;
err_sys("pthread_mutexattr_init error");
}
#ifdef _POSIX_THREAD_PROCESS_SHARED
void
Pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int flag)
{
int n;
if ( (n = pthread_mutexattr_setpshared(attr, flag)) == 0)
return;
errno = n;
err_sys("pthread_mutexattr_setpshared error");
}
#endif
void
Pthread_mutex_init(pthread_mutex_t *mptr, pthread_mutexattr_t *attr)
{
int n;
if ( (n = pthread_mutex_init(mptr, attr)) == 0)
return;
errno = n;
err_sys("pthread_mutex_init error");
}
/* include Pthread_mutex_lock */
void
Pthread_mutex_lock(pthread_mutex_t *mptr)
{
int n;
if ( (n = pthread_mutex_lock(mptr)) == 0)
return;
errno = n;
err_sys("pthread_mutex_lock error");
}
/* end Pthread_mutex_lock */
void
Pthread_mutex_unlock(pthread_mutex_t *mptr)
{
int n;
if ( (n = pthread_mutex_unlock(mptr)) == 0)
return;
errno = n;
err_sys("pthread_mutex_unlock error");
}
void
Pthread_cond_broadcast(pthread_cond_t *cptr)
{
int n;
if ( (n = pthread_cond_broadcast(cptr)) == 0)
return;
errno = n;
err_sys("pthread_cond_broadcast error");
}
void
Pthread_cond_signal(pthread_cond_t *cptr)
{
int n;
if ( (n = pthread_cond_signal(cptr)) == 0)
return;
errno = n;
err_sys("pthread_cond_signal error");
}
void
Pthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr)
{
int n;
if ( (n = pthread_cond_wait(cptr, mptr)) == 0)
return;
errno = n;
err_sys("pthread_cond_wait error");
}
void
Pthread_cond_timedwait(pthread_cond_t *cptr, pthread_mutex_t *mptr,
const struct timespec *tsptr)
{
int n;
if ( (n = pthread_cond_timedwait(cptr, mptr, tsptr)) == 0)
return;
errno = n;
err_sys("pthread_cond_timedwait error");
}
void
Pthread_once(pthread_once_t *ptr, void (*func)(void))
{
int n;
if ( (n = pthread_once(ptr, func)) == 0)
return;
errno = n;
err_sys("pthread_once error");
}
void
Pthread_key_create(pthread_key_t *key, void (*func)(void *))
{
int n;
if ( (n = pthread_key_create(key, func)) == 0)
return;
errno = n;
err_sys("pthread_key_create error");
}
void
Pthread_setspecific(pthread_key_t key, const void *value)
{
int n;
if ( (n = pthread_setspecific(key, value)) == 0)
return;
errno = n;
err_sys("pthread_setspecific error");
}