OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /** @file | 7 /** @file |
8 * Defines the API in the | 8 * Defines the API in the |
9 * <a href="group___pthread.html">Pthread library</a> | 9 * <a href="group___pthread.html">Pthread library</a> |
10 * | 10 * |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } pthread_cond_t; | 122 } pthread_cond_t; |
123 | 123 |
124 /** | 124 /** |
125 * A structure representing condition variable attributes. Currently | 125 * A structure representing condition variable attributes. Currently |
126 * Native Client condition variables have no attributes. | 126 * Native Client condition variables have no attributes. |
127 */ | 127 */ |
128 typedef struct { | 128 typedef struct { |
129 int dummy; /**< Reserved; condition variables don't have attributes */ | 129 int dummy; /**< Reserved; condition variables don't have attributes */ |
130 } pthread_condattr_t; | 130 } pthread_condattr_t; |
131 | 131 |
132 /** | |
133 * A structure representing a rwlock. It should be considered an | |
134 * opaque record; the names of the fields can change anytime. | |
135 */ | |
136 typedef struct { | |
137 pthread_mutex_t mutex; /* mutex for all values in the structure */ | |
138 int reader_count; | |
139 int writers_waiting; | |
140 struct __nc_basic_thread_data *writer_thread_id; | |
141 pthread_cond_t read_possible; | |
142 pthread_cond_t write_possible; | |
143 } pthread_rwlock_t; | |
144 | |
145 /** | |
146 * A structure representing rwlock attributes. It should be considered an | |
147 * opaque record. | |
148 */ | |
149 typedef struct { | |
150 int type; | |
151 } pthread_rwlockattr_t; | |
152 | |
153 /** A value that represents an uninitialized handle. */ | 132 /** A value that represents an uninitialized handle. */ |
154 #define NC_INVALID_HANDLE -1 | 133 #define NC_INVALID_HANDLE -1 |
155 | 134 |
156 /** Maximum valid thread ID value. */ | 135 /** Maximum valid thread ID value. */ |
157 #define MAX_THREAD_ID (0xfffffffe) | 136 #define MAX_THREAD_ID (0xfffffffe) |
158 | 137 |
159 /** Illegal thread ID value. */ | 138 /** Illegal thread ID value. */ |
160 #define NACL_PTHREAD_ILLEGAL_THREAD_ID ((pthread_t) 0) | 139 #define NACL_PTHREAD_ILLEGAL_THREAD_ID ((pthread_t) 0) |
161 | 140 |
162 /** Statically initializes a pthread_mutex_t representing a recursive mutex. */ | 141 /** Statically initializes a pthread_mutex_t representing a recursive mutex. */ |
163 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ | 142 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ |
164 {0, 1, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} | 143 {0, 1, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} |
165 /** Statically initializes a pthread_mutex_t representing a fast mutex. */ | 144 /** Statically initializes a pthread_mutex_t representing a fast mutex. */ |
166 #define PTHREAD_MUTEX_INITIALIZER \ | 145 #define PTHREAD_MUTEX_INITIALIZER \ |
167 {0, 0, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} | 146 {0, 0, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} |
168 /** | 147 /** |
169 * Statically initializes a pthread_mutex_t representing an | 148 * Statically initializes a pthread_mutex_t representing an |
170 * error-checking mutex. | 149 * error-checking mutex. |
171 */ | 150 */ |
172 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ | 151 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ |
173 {0, 2, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} | 152 {0, 2, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} |
174 /** Statically initializes a condition variable (pthread_cond_t). */ | 153 /** Statically initializes a condition variable (pthread_cond_t). */ |
175 #define PTHREAD_COND_INITIALIZER {0, NC_INVALID_HANDLE} | 154 #define PTHREAD_COND_INITIALIZER {0, NC_INVALID_HANDLE} |
176 | 155 |
177 #define PTHREAD_PROCESS_PRIVATE 0 | |
178 #define PTHREAD_PROCESS_SHARED 1 | |
179 | 156 |
180 | 157 |
181 /* Functions for mutex handling. */ | 158 /* Functions for mutex handling. */ |
182 | 159 |
183 /** @nqPosix | 160 /** @nqPosix |
184 * Initializes a mutex using attributes in mutex_attr, or using the | 161 * Initializes a mutex using attributes in mutex_attr, or using the |
185 * default values if the latter is NULL. | 162 * default values if the latter is NULL. |
186 * | 163 * |
187 * @linkPthread | 164 * @linkPthread |
188 * | 165 * |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 * when this function is called. | 346 * when this function is called. |
370 * @param abstime Absolute time specification; zero is the beginning of the epoch | 347 * @param abstime Absolute time specification; zero is the beginning of the epoch |
371 * (00:00:00 GMT, January 1, 1970). | 348 * (00:00:00 GMT, January 1, 1970). |
372 * | 349 * |
373 * @return 0 for success, non-zero error code otherwise. | 350 * @return 0 for success, non-zero error code otherwise. |
374 */ | 351 */ |
375 int pthread_cond_timedwait_abs(pthread_cond_t *cond, | 352 int pthread_cond_timedwait_abs(pthread_cond_t *cond, |
376 pthread_mutex_t *mutex, | 353 pthread_mutex_t *mutex, |
377 const struct timespec *abstime); | 354 const struct timespec *abstime); |
378 | 355 |
379 /** @nqPosix | 356 /** @nqPosix |
380 * Waits for condition variable cond to be signaled or broadcast; wait time is | 357 * Waits for condition variable cond to be signaled or broadcast; wait time is |
381 * limited by reltime. | 358 * limited by reltime. |
382 * | 359 * |
383 * @linkPthread | 360 * @linkPthread |
384 * | 361 * |
385 * @param cond Pointer to the condition variable structure. | 362 * @param cond Pointer to the condition variable structure. |
386 * @param mutex Pointer to the mutex structure. The mutex is assumed to be locked | 363 * @param mutex Pointer to the mutex structure. The mutex is assumed to be locked |
387 * when this function is called. | 364 * when this function is called. |
388 * @param reltime Time specification, relative to the current time. | 365 * @param reltime Time specification, relative to the current time. |
389 * | 366 * |
390 * @return 0 for success, non-zero error code otherwise. | 367 * @return 0 for success, non-zero error code otherwise. |
391 */ | 368 */ |
392 int pthread_cond_timedwait_rel(pthread_cond_t *cond, | 369 int pthread_cond_timedwait_rel(pthread_cond_t *cond, |
393 pthread_mutex_t *mutex, | 370 pthread_mutex_t *mutex, |
394 const struct timespec *reltime); | 371 const struct timespec *reltime); |
395 | 372 |
396 /** | 373 /** |
397 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually | 374 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually |
398 * a macro calling pthread_cond_timedwait_abs(). | 375 * a macro calling pthread_cond_timedwait_abs(). |
399 */ | 376 */ |
400 #define pthread_cond_timedwait pthread_cond_timedwait_abs | 377 #define pthread_cond_timedwait pthread_cond_timedwait_abs |
401 | 378 |
402 /* Functions for rwlock handling. */ | |
403 | |
404 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr); | |
405 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, | |
406 int *pshared); | |
407 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared); | |
408 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); | |
409 | |
410 int pthread_rwlock_init(pthread_rwlock_t *rwlock, | |
411 const pthread_rwlockattr_t *attr); | |
412 | |
413 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); | |
414 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); | |
415 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, | |
416 const struct timespec *abstime); | |
417 | |
418 | |
419 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); | |
420 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); | |
421 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, | |
422 const struct timespec *abstime); | |
423 | |
424 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); | |
425 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); | |
426 | |
427 | 379 |
428 /* Threads */ | 380 /* Threads */ |
429 /** Thread entry function type. */ | 381 /** Thread entry function type. */ |
430 typedef void *(*nc_thread_function)(void *p); | 382 typedef void *(*nc_thread_function)(void *p); |
431 /** Thread identifier type. */ | 383 /** Thread identifier type. */ |
432 typedef struct __nc_basic_thread_data *pthread_t; | 384 typedef struct __nc_basic_thread_data *pthread_t; |
433 | 385 |
434 /** A structure representing thread attributes. */ | 386 /** A structure representing thread attributes. */ |
435 typedef struct { | 387 typedef struct { |
436 int joinable; /**< 1 if the thread is joinable, 0 otherwise */ | 388 int joinable; /**< 1 if the thread is joinable, 0 otherwise */ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 * | 492 * |
541 * @param thread_id The identifier of the thread to receive the signal. | 493 * @param thread_id The identifier of the thread to receive the signal. |
542 * @param sig The signal value to send. | 494 * @param sig The signal value to send. |
543 * | 495 * |
544 * @return 0 for success, non-zero error code otherwise. | 496 * @return 0 for success, non-zero error code otherwise. |
545 */ | 497 */ |
546 extern int pthread_kill(pthread_t thread_id, | 498 extern int pthread_kill(pthread_t thread_id, |
547 int sig); | 499 int sig); |
548 | 500 |
549 /* Functions for handling thread attributes. */ | 501 /* Functions for handling thread attributes. */ |
550 | |
551 /** @nqPosix | 502 /** @nqPosix |
552 * Initializes thread attributes structure attr with default attributes | 503 * Initializes thread attributes structure attr with default attributes |
553 * (detachstate is PTHREAD_CREATE_JOINABLE). | 504 * (detachstate is PTHREAD_CREATE_JOINABLE). |
554 * | 505 * |
555 * @linkPthread | 506 * @linkPthread |
556 * | 507 * |
557 * @param attr Pointer to thread attributes structure. | 508 * @param attr Pointer to thread attributes structure. |
558 * | 509 * |
559 * @return 0 on success, non-zero error code otherwise. | 510 * @return 0 on success, non-zero error code otherwise. |
560 */ | 511 */ |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 | 742 |
792 /** | 743 /** |
793 * @} End of PTHREAD group | 744 * @} End of PTHREAD group |
794 */ | 745 */ |
795 | 746 |
796 #ifdef __cplusplus | 747 #ifdef __cplusplus |
797 } | 748 } |
798 #endif | 749 #endif |
799 | 750 |
800 #endif /* pthread.h */ | 751 #endif /* pthread.h */ |
OLD | NEW |