| 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 |
| 132 /** A value that represents an uninitialized handle. */ | 153 /** A value that represents an uninitialized handle. */ |
| 133 #define NC_INVALID_HANDLE -1 | 154 #define NC_INVALID_HANDLE -1 |
| 134 | 155 |
| 135 /** Maximum valid thread ID value. */ | 156 /** Maximum valid thread ID value. */ |
| 136 #define MAX_THREAD_ID (0xfffffffe) | 157 #define MAX_THREAD_ID (0xfffffffe) |
| 137 | 158 |
| 138 /** Illegal thread ID value. */ | 159 /** Illegal thread ID value. */ |
| 139 #define NACL_PTHREAD_ILLEGAL_THREAD_ID ((pthread_t) 0) | 160 #define NACL_PTHREAD_ILLEGAL_THREAD_ID ((pthread_t) 0) |
| 140 | 161 |
| 141 /** Statically initializes a pthread_mutex_t representing a recursive mutex. */ | 162 /** Statically initializes a pthread_mutex_t representing a recursive mutex. */ |
| 142 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ | 163 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ |
| 143 {0, 1, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} | 164 {0, 1, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} |
| 144 /** Statically initializes a pthread_mutex_t representing a fast mutex. */ | 165 /** Statically initializes a pthread_mutex_t representing a fast mutex. */ |
| 145 #define PTHREAD_MUTEX_INITIALIZER \ | 166 #define PTHREAD_MUTEX_INITIALIZER \ |
| 146 {0, 0, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} | 167 {0, 0, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} |
| 147 /** | 168 /** |
| 148 * Statically initializes a pthread_mutex_t representing an | 169 * Statically initializes a pthread_mutex_t representing an |
| 149 * error-checking mutex. | 170 * error-checking mutex. |
| 150 */ | 171 */ |
| 151 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ | 172 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ |
| 152 {0, 2, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} | 173 {0, 2, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} |
| 153 /** Statically initializes a condition variable (pthread_cond_t). */ | 174 /** Statically initializes a condition variable (pthread_cond_t). */ |
| 154 #define PTHREAD_COND_INITIALIZER {0, NC_INVALID_HANDLE} | 175 #define PTHREAD_COND_INITIALIZER {0, NC_INVALID_HANDLE} |
| 155 | 176 |
| 177 #define PTHREAD_PROCESS_PRIVATE 0 |
| 178 #define PTHREAD_PROCESS_SHARED 1 |
| 156 | 179 |
| 157 | 180 |
| 158 /* Functions for mutex handling. */ | 181 /* Functions for mutex handling. */ |
| 159 | 182 |
| 160 /** @nqPosix | 183 /** @nqPosix |
| 161 * Initializes a mutex using attributes in mutex_attr, or using the | 184 * Initializes a mutex using attributes in mutex_attr, or using the |
| 162 * default values if the latter is NULL. | 185 * default values if the latter is NULL. |
| 163 * | 186 * |
| 164 * @linkPthread | 187 * @linkPthread |
| 165 * | 188 * |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 * when this function is called. | 369 * when this function is called. |
| 347 * @param abstime Absolute time specification; zero is the beginning of the epoch | 370 * @param abstime Absolute time specification; zero is the beginning of the epoch |
| 348 * (00:00:00 GMT, January 1, 1970). | 371 * (00:00:00 GMT, January 1, 1970). |
| 349 * | 372 * |
| 350 * @return 0 for success, non-zero error code otherwise. | 373 * @return 0 for success, non-zero error code otherwise. |
| 351 */ | 374 */ |
| 352 int pthread_cond_timedwait_abs(pthread_cond_t *cond, | 375 int pthread_cond_timedwait_abs(pthread_cond_t *cond, |
| 353 pthread_mutex_t *mutex, | 376 pthread_mutex_t *mutex, |
| 354 const struct timespec *abstime); | 377 const struct timespec *abstime); |
| 355 | 378 |
| 356 /** @nqPosix | 379 /** @nqPosix |
| 357 * Waits for condition variable cond to be signaled or broadcast; wait time is | 380 * Waits for condition variable cond to be signaled or broadcast; wait time is |
| 358 * limited by reltime. | 381 * limited by reltime. |
| 359 * | 382 * |
| 360 * @linkPthread | 383 * @linkPthread |
| 361 * | 384 * |
| 362 * @param cond Pointer to the condition variable structure. | 385 * @param cond Pointer to the condition variable structure. |
| 363 * @param mutex Pointer to the mutex structure. The mutex is assumed to be locked | 386 * @param mutex Pointer to the mutex structure. The mutex is assumed to be locked |
| 364 * when this function is called. | 387 * when this function is called. |
| 365 * @param reltime Time specification, relative to the current time. | 388 * @param reltime Time specification, relative to the current time. |
| 366 * | 389 * |
| 367 * @return 0 for success, non-zero error code otherwise. | 390 * @return 0 for success, non-zero error code otherwise. |
| 368 */ | 391 */ |
| 369 int pthread_cond_timedwait_rel(pthread_cond_t *cond, | 392 int pthread_cond_timedwait_rel(pthread_cond_t *cond, |
| 370 pthread_mutex_t *mutex, | 393 pthread_mutex_t *mutex, |
| 371 const struct timespec *reltime); | 394 const struct timespec *reltime); |
| 372 | 395 |
| 373 /** | 396 /** |
| 374 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually | 397 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually |
| 375 * a macro calling pthread_cond_timedwait_abs(). | 398 * a macro calling pthread_cond_timedwait_abs(). |
| 376 */ | 399 */ |
| 377 #define pthread_cond_timedwait pthread_cond_timedwait_abs | 400 #define pthread_cond_timedwait pthread_cond_timedwait_abs |
| 378 | 401 |
| 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 |
| 379 | 427 |
| 380 /* Threads */ | 428 /* Threads */ |
| 381 /** Thread entry function type. */ | 429 /** Thread entry function type. */ |
| 382 typedef void *(*nc_thread_function)(void *p); | 430 typedef void *(*nc_thread_function)(void *p); |
| 383 /** Thread identifier type. */ | 431 /** Thread identifier type. */ |
| 384 typedef struct __nc_basic_thread_data *pthread_t; | 432 typedef struct __nc_basic_thread_data *pthread_t; |
| 385 | 433 |
| 386 /** A structure representing thread attributes. */ | 434 /** A structure representing thread attributes. */ |
| 387 typedef struct { | 435 typedef struct { |
| 388 int joinable; /**< 1 if the thread is joinable, 0 otherwise */ | 436 int joinable; /**< 1 if the thread is joinable, 0 otherwise */ |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 * | 540 * |
| 493 * @param thread_id The identifier of the thread to receive the signal. | 541 * @param thread_id The identifier of the thread to receive the signal. |
| 494 * @param sig The signal value to send. | 542 * @param sig The signal value to send. |
| 495 * | 543 * |
| 496 * @return 0 for success, non-zero error code otherwise. | 544 * @return 0 for success, non-zero error code otherwise. |
| 497 */ | 545 */ |
| 498 extern int pthread_kill(pthread_t thread_id, | 546 extern int pthread_kill(pthread_t thread_id, |
| 499 int sig); | 547 int sig); |
| 500 | 548 |
| 501 /* Functions for handling thread attributes. */ | 549 /* Functions for handling thread attributes. */ |
| 550 |
| 502 /** @nqPosix | 551 /** @nqPosix |
| 503 * Initializes thread attributes structure attr with default attributes | 552 * Initializes thread attributes structure attr with default attributes |
| 504 * (detachstate is PTHREAD_CREATE_JOINABLE). | 553 * (detachstate is PTHREAD_CREATE_JOINABLE). |
| 505 * | 554 * |
| 506 * @linkPthread | 555 * @linkPthread |
| 507 * | 556 * |
| 508 * @param attr Pointer to thread attributes structure. | 557 * @param attr Pointer to thread attributes structure. |
| 509 * | 558 * |
| 510 * @return 0 on success, non-zero error code otherwise. | 559 * @return 0 on success, non-zero error code otherwise. |
| 511 */ | 560 */ |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 791 |
| 743 /** | 792 /** |
| 744 * @} End of PTHREAD group | 793 * @} End of PTHREAD group |
| 745 */ | 794 */ |
| 746 | 795 |
| 747 #ifdef __cplusplus | 796 #ifdef __cplusplus |
| 748 } | 797 } |
| 749 #endif | 798 #endif |
| 750 | 799 |
| 751 #endif /* pthread.h */ | 800 #endif /* pthread.h */ |
| OLD | NEW |