Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: src/untrusted/pthread/pthread.h

Issue 623863002: Implement pthread_rwlock functions for NaCl newlib. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: spellcheck Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
156 177 #define PTHREAD_PROCESS_PRIVATE 0
178 #define PTHREAD_PROCESS_SHARED 1
157 179
Mark Seaborn 2014/12/01 22:33:07 Nit: add empty line to maintain spacing between se
Sam Clegg 2014/12/10 19:17:43 Done.
158 /* Functions for mutex handling. */ 180 /* Functions for mutex handling. */
159 181
160 /** @nqPosix 182 /** @nqPosix
161 * Initializes a mutex using attributes in mutex_attr, or using the 183 * Initializes a mutex using attributes in mutex_attr, or using the
162 * default values if the latter is NULL. 184 * default values if the latter is NULL.
163 * 185 *
164 * @linkPthread 186 * @linkPthread
165 * 187 *
166 * @param mutex The address of the mutex structure to be initialized. 188 * @param mutex The address of the mutex structure to be initialized.
167 * @param mutex_attr The address of the attributes structure. 189 * @param mutex_attr The address of the attributes structure.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 int pthread_cond_timedwait_rel(pthread_cond_t *cond, 391 int pthread_cond_timedwait_rel(pthread_cond_t *cond,
370 pthread_mutex_t *mutex, 392 pthread_mutex_t *mutex,
371 const struct timespec *reltime); 393 const struct timespec *reltime);
372 394
373 /** 395 /**
374 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually 396 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually
375 * a macro calling pthread_cond_timedwait_abs(). 397 * a macro calling pthread_cond_timedwait_abs().
376 */ 398 */
377 #define pthread_cond_timedwait pthread_cond_timedwait_abs 399 #define pthread_cond_timedwait pthread_cond_timedwait_abs
378 400
401 /* Functions for rwlock handling. */
402
403 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
404 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr,
405 int *pshared);
406 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared);
407 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
408
409 int pthread_rwlock_init(pthread_rwlock_t *rwlock,
410 const pthread_rwlockattr_t *attr);
411
412 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
413 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
414 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
415 const struct timespec *abstime);
416
417
418 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
419 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
420 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
421 const struct timespec *abstime);
422
423 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
424 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
379 425
Mark Seaborn 2014/12/01 22:33:07 Nit: add empty line to maintain spacing between se
Sam Clegg 2014/12/10 19:17:43 Done.
380 /* Threads */ 426 /* Threads */
381 /** Thread entry function type. */ 427 /** Thread entry function type. */
382 typedef void *(*nc_thread_function)(void *p); 428 typedef void *(*nc_thread_function)(void *p);
383 /** Thread identifier type. */ 429 /** Thread identifier type. */
384 typedef struct __nc_basic_thread_data *pthread_t; 430 typedef struct __nc_basic_thread_data *pthread_t;
385 431
386 /** A structure representing thread attributes. */ 432 /** A structure representing thread attributes. */
387 typedef struct { 433 typedef struct {
388 int joinable; /**< 1 if the thread is joinable, 0 otherwise */ 434 int joinable; /**< 1 if the thread is joinable, 0 otherwise */
389 size_t stacksize; /**< The requested thread stack size in bytes. */ 435 size_t stacksize; /**< The requested thread stack size in bytes. */
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 756
711 /** 757 /**
712 * @} End of PTHREAD group 758 * @} End of PTHREAD group
713 */ 759 */
714 760
715 #ifdef __cplusplus 761 #ifdef __cplusplus
716 } 762 }
717 #endif 763 #endif
718 764
719 #endif /* pthread.h */ 765 #endif /* pthread.h */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698