Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/head/pthread.h
+++ new/usr/src/head/pthread.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 - * Copyright 2016 Joyent, Inc.
24 + * Copyright 2018 Joyent, Inc.
25 25 *
26 26 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 30 #ifndef _PTHREAD_H
31 31 #define _PTHREAD_H
32 32
33 33 #include <sys/feature_tests.h>
34 34
35 35 #ifndef _ASM
36 36 #include <sys/types.h>
37 37 #include <time.h>
38 38 #include <sched.h>
39 39 #endif /* _ASM */
40 40
41 41 #ifdef __cplusplus
42 42 extern "C" {
43 43 #endif
44 44
45 45 /*
46 46 * Thread related attribute values defined as in thread.h.
47 47 * These are defined as bit pattern in thread.h.
48 48 * Any change here should be reflected in thread.h.
49 49 */
50 50 /* detach */
51 51 #define PTHREAD_CREATE_DETACHED 0x40 /* = THR_DETACHED */
52 52 #define PTHREAD_CREATE_JOINABLE 0
53 53 /* scope */
54 54 #define PTHREAD_SCOPE_SYSTEM 0x01 /* = THR_BOUND */
55 55 #define PTHREAD_SCOPE_PROCESS 0
56 56
57 57 /*
58 58 * Other attributes which are not defined in thread.h
59 59 */
60 60 /* inherit */
61 61 #define PTHREAD_INHERIT_SCHED 1
62 62 #define PTHREAD_EXPLICIT_SCHED 0
63 63
64 64 /*
65 65 * Value of process-shared attribute
66 66 * These are defined as values defined in sys/synch.h
67 67 * Any change here should be reflected in sys/synch.h.
68 68 */
69 69 #define PTHREAD_PROCESS_SHARED 1 /* = USYNC_PROCESS */
70 70 #define PTHREAD_PROCESS_PRIVATE 0 /* = USYNC_THREAD */
71 71
72 72 /*
73 73 * mutex types
74 74 * keep these in synch which sys/synch.h lock flags
75 75 */
76 76 #define PTHREAD_MUTEX_NORMAL 0x0
77 77 #define PTHREAD_MUTEX_ERRORCHECK 0x2
78 78 #define PTHREAD_MUTEX_RECURSIVE 0x4
79 79 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
80 80
81 81 /*
82 82 * Mutex protocol values. Keep these in synch with sys/synch.h lock types.
83 83 */
84 84 #define PTHREAD_PRIO_NONE 0x0
85 85 #define PTHREAD_PRIO_INHERIT 0x10
86 86 #define PTHREAD_PRIO_PROTECT 0x20
87 87
88 88 /*
89 89 * Mutex robust attribute values.
90 90 * Keep these in synch with sys/synch.h lock types.
91 91 */
92 92 #define PTHREAD_MUTEX_STALLED 0x0
93 93 #define PTHREAD_MUTEX_ROBUST 0x40
94 94 /*
95 95 * Historical solaris-specific names,
96 96 * from before pthread_mutexattr_getrobust() became standardized
97 97 */
98 98 #define PTHREAD_MUTEX_STALL_NP PTHREAD_MUTEX_STALLED
99 99 #define PTHREAD_MUTEX_ROBUST_NP PTHREAD_MUTEX_ROBUST
100 100
101 101 /*
102 102 * macros - default initializers defined as in synch.h
103 103 * Any change here should be reflected in synch.h.
104 104 *
105 105 * NOTE:
106 106 * Make sure that any change in the macros is consistent with the definition
107 107 * of the corresponding types in sys/types.h (e.g. PTHREAD_MUTEX_INITIALIZER
108 108 * should be consistent with the definition for pthread_mutex_t).
109 109 */
110 110 #define PTHREAD_MUTEX_INITIALIZER /* = DEFAULTMUTEX */ \
111 111 {{0, 0, 0, PTHREAD_PROCESS_PRIVATE, _MUTEX_MAGIC}, {{{0}}}, 0}
112 112
113 113 #define PTHREAD_COND_INITIALIZER /* = DEFAULTCV */ \
114 114 {{{0, 0, 0, 0}, PTHREAD_PROCESS_PRIVATE, _COND_MAGIC}, 0}
115 115
116 116 #define PTHREAD_RWLOCK_INITIALIZER /* = DEFAULTRWLOCK */ \
117 117 {0, PTHREAD_PROCESS_PRIVATE, _RWL_MAGIC, PTHREAD_MUTEX_INITIALIZER, \
118 118 PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER}
119 119
120 120 /* cancellation type and state */
121 121 #define PTHREAD_CANCEL_ENABLE 0x00
122 122 #define PTHREAD_CANCEL_DISABLE 0x01
123 123 #define PTHREAD_CANCEL_DEFERRED 0x00
124 124 #define PTHREAD_CANCEL_ASYNCHRONOUS 0x02
125 125 #define PTHREAD_CANCELED (void *)-19
126 126
127 127 /* pthread_once related values */
128 128 #define PTHREAD_ONCE_NOTDONE 0
129 129 #define PTHREAD_ONCE_DONE 1
130 130 #define PTHREAD_ONCE_INIT { {0, 0, 0, PTHREAD_ONCE_NOTDONE} }
131 131
↓ open down ↓ |
97 lines elided |
↑ open up ↑ |
132 132 /*
133 133 * The key to be created by pthread_key_create_once_np()
134 134 * must be statically initialized with PTHREAD_ONCE_KEY_NP.
135 135 * This must be the same as THR_ONCE_KEY in <thread.h>
136 136 */
137 137 #define PTHREAD_ONCE_KEY_NP (pthread_key_t)(-1)
138 138
139 139 /* barriers */
140 140 #define PTHREAD_BARRIER_SERIAL_THREAD -2
141 141
142 +/* For pthread_{get,set}name_np(). */
143 +#define PTHREAD_MAX_NAMELEN_NP (32)
144 +
142 145 #ifndef _ASM
143 146
144 147 /*
145 148 * cancellation cleanup structure
146 149 */
147 150 typedef struct _cleanup {
148 151 uintptr_t pthread_cleanup_pad[4];
149 152 } _cleanup_t;
150 153
151 154 void __pthread_cleanup_push(void (*)(void *), void *, caddr_t, _cleanup_t *);
152 155 void __pthread_cleanup_pop(int, _cleanup_t *);
153 156 caddr_t _getfp(void);
154 157
155 158 #if __cplusplus
156 159 extern "C" {
157 160 #endif
158 161
159 162 typedef void (*_Voidfp)(void*); /* pointer to extern "C" function */
160 163
161 164 #if __cplusplus
162 165 } /* extern "C" */
163 166 #endif
164 167
165 168 #define pthread_cleanup_push(routine, args) { \
166 169 _cleanup_t _cleanup_info; \
167 170 __pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \
168 171 (caddr_t)_getfp(), &_cleanup_info);
169 172
170 173 #define pthread_cleanup_pop(ex) \
171 174 __pthread_cleanup_pop(ex, &_cleanup_info); \
172 175 }
173 176
174 177 /*
175 178 * function prototypes - thread related calls
176 179 */
177 180
178 181 /*
179 182 * pthread_atfork() is also declared in <unistd.h> as per SUSv2. The
180 183 * declarations are identical. A change to either one may also require
181 184 * appropriate namespace updates in order to avoid redeclaration
182 185 * warnings in the case where both prototypes are exposed via inclusion
183 186 * of both <pthread.h> and <unistd.h>.
184 187 */
185 188 extern int pthread_atfork(void (*) (void), void (*) (void), void (*) (void));
186 189 extern int pthread_attr_init(pthread_attr_t *);
187 190 extern int pthread_attr_destroy(pthread_attr_t *);
188 191 extern int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
189 192 extern int pthread_attr_getstack(const pthread_attr_t *_RESTRICT_KYWD,
190 193 void **_RESTRICT_KYWD, size_t *_RESTRICT_KYWD);
191 194 extern int pthread_attr_setstacksize(pthread_attr_t *, size_t);
192 195 extern int pthread_attr_getstacksize(const pthread_attr_t *_RESTRICT_KYWD,
193 196 size_t *_RESTRICT_KYWD);
194 197 extern int pthread_attr_setstackaddr(pthread_attr_t *, void *);
195 198 extern int pthread_attr_getstackaddr(const pthread_attr_t *_RESTRICT_KYWD,
196 199 void **_RESTRICT_KYWD);
197 200 extern int pthread_attr_setdetachstate(pthread_attr_t *, int);
198 201 extern int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
199 202 extern int pthread_attr_setscope(pthread_attr_t *, int);
200 203 extern int pthread_attr_getscope(const pthread_attr_t *_RESTRICT_KYWD,
201 204 int *_RESTRICT_KYWD);
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
202 205 extern int pthread_attr_setinheritsched(pthread_attr_t *, int);
203 206 extern int pthread_attr_getinheritsched(const pthread_attr_t *_RESTRICT_KYWD,
204 207 int *_RESTRICT_KYWD);
205 208 extern int pthread_attr_setschedpolicy(pthread_attr_t *, int);
206 209 extern int pthread_attr_getschedpolicy(const pthread_attr_t *_RESTRICT_KYWD,
207 210 int *_RESTRICT_KYWD);
208 211 extern int pthread_attr_setschedparam(pthread_attr_t *_RESTRICT_KYWD,
209 212 const struct sched_param *_RESTRICT_KYWD);
210 213 extern int pthread_attr_getschedparam(const pthread_attr_t *_RESTRICT_KYWD,
211 214 struct sched_param *_RESTRICT_KYWD);
215 +extern int pthread_attr_setname_np(pthread_attr_t *_RESTRICT_KYWD,
216 + const char *_RESTRICT_KYWD);
217 +extern int pthread_attr_getname_np(pthread_attr_t *_RESTRICT_KYWD,
218 + char *_RESTRICT_KYWD, size_t);
212 219 extern int pthread_create(pthread_t *_RESTRICT_KYWD,
213 220 const pthread_attr_t *_RESTRICT_KYWD, void * (*)(void *),
214 221 void *_RESTRICT_KYWD);
215 222 extern int pthread_once(pthread_once_t *, void (*)(void));
216 223 extern int pthread_join(pthread_t, void **);
217 224 extern int pthread_detach(pthread_t);
218 225 extern void pthread_exit(void *) __NORETURN;
219 226 extern int pthread_cancel(pthread_t);
220 227 extern int pthread_setschedparam(pthread_t, int, const struct sched_param *);
221 228 extern int pthread_getschedparam(pthread_t, int *_RESTRICT_KYWD,
222 229 struct sched_param *_RESTRICT_KYWD);
223 230 extern int pthread_setschedprio(pthread_t, int);
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
224 231 extern int pthread_setcancelstate(int, int *);
225 232 extern int pthread_setcanceltype(int, int *);
226 233 extern void pthread_testcancel(void);
227 234 extern int pthread_equal(pthread_t, pthread_t);
228 235 extern int pthread_key_create(pthread_key_t *, void (*)(void *));
229 236 extern int pthread_key_create_once_np(pthread_key_t *, void (*)(void *));
230 237 extern int pthread_key_delete(pthread_key_t);
231 238 extern int pthread_setspecific(pthread_key_t, const void *);
232 239 extern void *pthread_getspecific(pthread_key_t);
233 240 extern pthread_t pthread_self(void);
241 +extern int pthread_setname_np(pthread_t, const char *);
242 +extern int pthread_getname_np(pthread_t, char *, size_t);
234 243
235 244 /*
236 245 * function prototypes - synchronization related calls
237 246 */
238 247 extern int pthread_mutexattr_init(pthread_mutexattr_t *);
239 248 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *);
240 249 extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
241 250 extern int pthread_mutexattr_getpshared(
242 251 const pthread_mutexattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
243 252 extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
244 253 extern int pthread_mutexattr_getprotocol(
245 254 const pthread_mutexattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
246 255 extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
247 256 extern int pthread_mutexattr_getprioceiling(
248 257 const pthread_mutexattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
249 258 extern int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
250 259 extern int pthread_mutexattr_getrobust(
251 260 const pthread_mutexattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
252 261 extern int pthread_mutex_init(pthread_mutex_t *_RESTRICT_KYWD,
253 262 const pthread_mutexattr_t *_RESTRICT_KYWD);
254 263 extern int pthread_mutex_consistent(pthread_mutex_t *);
255 264 extern int pthread_mutex_destroy(pthread_mutex_t *);
256 265 extern int pthread_mutex_lock(pthread_mutex_t *);
257 266 extern int pthread_mutex_timedlock(pthread_mutex_t *_RESTRICT_KYWD,
258 267 const struct timespec *_RESTRICT_KYWD);
259 268 extern int pthread_mutex_reltimedlock_np(pthread_mutex_t *_RESTRICT_KYWD,
260 269 const struct timespec *_RESTRICT_KYWD);
261 270 extern int pthread_mutex_unlock(pthread_mutex_t *);
262 271 extern int pthread_mutex_trylock(pthread_mutex_t *);
263 272 extern int pthread_mutex_setprioceiling(pthread_mutex_t *_RESTRICT_KYWD,
264 273 int, int *_RESTRICT_KYWD);
265 274 extern int pthread_mutex_getprioceiling(const pthread_mutex_t *_RESTRICT_KYWD,
266 275 int *_RESTRICT_KYWD);
267 276 extern int pthread_condattr_init(pthread_condattr_t *);
268 277 extern int pthread_condattr_destroy(pthread_condattr_t *);
269 278 extern int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
270 279 extern int pthread_condattr_getclock(const pthread_condattr_t *_RESTRICT_KYWD,
271 280 clockid_t *_RESTRICT_KYWD);
272 281 extern int pthread_condattr_setpshared(pthread_condattr_t *, int);
273 282 extern int pthread_condattr_getpshared(const pthread_condattr_t *_RESTRICT_KYWD,
274 283 int *_RESTRICT_KYWD);
275 284 extern int pthread_cond_init(pthread_cond_t *_RESTRICT_KYWD,
276 285 const pthread_condattr_t *_RESTRICT_KYWD);
277 286 extern int pthread_cond_destroy(pthread_cond_t *);
278 287 extern int pthread_cond_broadcast(pthread_cond_t *);
279 288 extern int pthread_cond_signal(pthread_cond_t *);
280 289 extern int pthread_cond_wait(pthread_cond_t *_RESTRICT_KYWD,
281 290 pthread_mutex_t *_RESTRICT_KYWD);
282 291 extern int pthread_cond_timedwait(pthread_cond_t *_RESTRICT_KYWD,
283 292 pthread_mutex_t *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD);
284 293 extern int pthread_cond_reltimedwait_np(pthread_cond_t *_RESTRICT_KYWD,
285 294 pthread_mutex_t *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD);
286 295 extern int pthread_attr_getguardsize(const pthread_attr_t *_RESTRICT_KYWD,
287 296 size_t *_RESTRICT_KYWD);
288 297 extern int pthread_attr_setguardsize(pthread_attr_t *, size_t);
289 298 extern int pthread_getconcurrency(void);
290 299 extern int pthread_setconcurrency(int);
291 300 extern int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
292 301 extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *_RESTRICT_KYWD,
293 302 int *_RESTRICT_KYWD);
294 303 extern int pthread_rwlock_init(pthread_rwlock_t *_RESTRICT_KYWD,
295 304 const pthread_rwlockattr_t *_RESTRICT_KYWD);
296 305 extern int pthread_rwlock_destroy(pthread_rwlock_t *);
297 306 extern int pthread_rwlock_rdlock(pthread_rwlock_t *);
298 307 extern int pthread_rwlock_timedrdlock(pthread_rwlock_t *_RESTRICT_KYWD,
299 308 const struct timespec *_RESTRICT_KYWD);
300 309 extern int pthread_rwlock_reltimedrdlock_np(pthread_rwlock_t *_RESTRICT_KYWD,
301 310 const struct timespec *_RESTRICT_KYWD);
302 311 extern int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
303 312 extern int pthread_rwlock_wrlock(pthread_rwlock_t *);
304 313 extern int pthread_rwlock_timedwrlock(pthread_rwlock_t *_RESTRICT_KYWD,
305 314 const struct timespec *_RESTRICT_KYWD);
306 315 extern int pthread_rwlock_reltimedwrlock_np(pthread_rwlock_t *_RESTRICT_KYWD,
307 316 const struct timespec *_RESTRICT_KYWD);
308 317 extern int pthread_rwlock_trywrlock(pthread_rwlock_t *);
309 318 extern int pthread_rwlock_unlock(pthread_rwlock_t *);
310 319 extern int pthread_rwlockattr_init(pthread_rwlockattr_t *);
311 320 extern int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
312 321 extern int pthread_rwlockattr_getpshared(
313 322 const pthread_rwlockattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
314 323 extern int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
315 324 extern int pthread_spin_init(pthread_spinlock_t *, int);
316 325 extern int pthread_spin_destroy(pthread_spinlock_t *);
317 326 extern int pthread_spin_lock(pthread_spinlock_t *);
318 327 extern int pthread_spin_trylock(pthread_spinlock_t *);
319 328 extern int pthread_spin_unlock(pthread_spinlock_t *);
320 329 extern int pthread_barrierattr_init(pthread_barrierattr_t *);
321 330 extern int pthread_barrierattr_destroy(pthread_barrierattr_t *);
322 331 extern int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
323 332 extern int pthread_barrierattr_getpshared(
324 333 const pthread_barrierattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
325 334 extern int pthread_barrier_init(pthread_barrier_t *_RESTRICT_KYWD,
326 335 const pthread_barrierattr_t *_RESTRICT_KYWD, uint_t);
327 336 extern int pthread_barrier_destroy(pthread_barrier_t *);
328 337 extern int pthread_barrier_wait(pthread_barrier_t *);
329 338
330 339 /* Historical names -- present only for binary compatibility */
331 340 extern int pthread_mutex_consistent_np(pthread_mutex_t *);
332 341 extern int pthread_mutexattr_setrobust_np(pthread_mutexattr_t *, int);
333 342 extern int pthread_mutexattr_getrobust_np(
334 343 const pthread_mutexattr_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
335 344
336 345 /*
337 346 * These are non-standardized extensions that we provide. Their origins are
338 347 * documented in their manual pages.
339 348 */
340 349 #if !defined(_STRICT_SYMBOLS) || defined(__EXTENSIONS__)
341 350 extern int pthread_attr_get_np(pthread_t, pthread_attr_t *);
342 351 #endif /* !_STRICT_SYMBOLS || __EXTENSIONS__ */
343 352
344 353 #endif /* _ASM */
345 354
346 355 #ifdef __cplusplus
347 356 }
348 357 #endif
349 358
350 359 #endif /* _PTHREAD_H */
↓ open down ↓ |
107 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX