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

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

Issue 609363003: Add implementation of pthread_rwlock based on NaCl futexs (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: 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
« no previous file with comments | « src/untrusted/pthread/nc_rwlock.c ('k') | src/untrusted/pthread/pthread.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 rwlock attributes. It should be considered an
134 * opaque record.
135 */
136 typedef int32_t pthread_rwlockattr_t;
137
138 /**
139 * A structure representing a rwlock. It should be considered an
140 * opaque record; the names of the fields can change anytime.
141 */
142 typedef struct {
143 volatile int32_t state; /* 0=unlock, -1=writer lock, +n=reader lock */
144 struct __nc_basic_thread_data *volatile writer_thread_id;
145 volatile int32_t pending_readers;
146 volatile int32_t pending_writers;
147 pthread_rwlockattr_t attr;
148 } pthread_rwlock_t;
149
132 /** A value that represents an uninitialized handle. */ 150 /** A value that represents an uninitialized handle. */
133 #define NC_INVALID_HANDLE -1 151 #define NC_INVALID_HANDLE -1
134 152
135 /** Maximum valid thread ID value. */ 153 /** Maximum valid thread ID value. */
136 #define MAX_THREAD_ID (0xfffffffe) 154 #define MAX_THREAD_ID (0xfffffffe)
137 155
138 /** Illegal thread ID value. */ 156 /** Illegal thread ID value. */
139 #define NACL_PTHREAD_ILLEGAL_THREAD_ID ((pthread_t) 0) 157 #define NACL_PTHREAD_ILLEGAL_THREAD_ID ((pthread_t) 0)
140 158
141 /** Statically initializes a pthread_mutex_t representing a recursive mutex. */ 159 /** Statically initializes a pthread_mutex_t representing a recursive mutex. */
142 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ 160 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
143 {0, 1, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} 161 {0, 1, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE}
144 /** Statically initializes a pthread_mutex_t representing a fast mutex. */ 162 /** Statically initializes a pthread_mutex_t representing a fast mutex. */
145 #define PTHREAD_MUTEX_INITIALIZER \ 163 #define PTHREAD_MUTEX_INITIALIZER \
146 {0, 0, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} 164 {0, 0, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE}
147 /** 165 /**
148 * Statically initializes a pthread_mutex_t representing an 166 * Statically initializes a pthread_mutex_t representing an
149 * error-checking mutex. 167 * error-checking mutex.
150 */ 168 */
151 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ 169 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
152 {0, 2, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE} 170 {0, 2, NACL_PTHREAD_ILLEGAL_THREAD_ID, 0, NC_INVALID_HANDLE}
153 /** Statically initializes a condition variable (pthread_cond_t). */ 171 /** Statically initializes a condition variable (pthread_cond_t). */
154 #define PTHREAD_COND_INITIALIZER {0, NC_INVALID_HANDLE} 172 #define PTHREAD_COND_INITIALIZER {0, NC_INVALID_HANDLE}
155 173
156 174 #define PTHREAD_PROCESS_PRIVATE 0
175 #define PTHREAD_PROCESS_SHARED 1
157 176
158 /* Functions for mutex handling. */ 177 /* Functions for mutex handling. */
159 178
160 /** @nqPosix 179 /** @nqPosix
161 * Initializes a mutex using attributes in mutex_attr, or using the 180 * Initializes a mutex using attributes in mutex_attr, or using the
162 * default values if the latter is NULL. 181 * default values if the latter is NULL.
163 * 182 *
164 * @linkPthread 183 * @linkPthread
165 * 184 *
166 * @param mutex The address of the mutex structure to be initialized. 185 * @param mutex The address of the mutex structure to be initialized.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 int pthread_cond_timedwait_rel(pthread_cond_t *cond, 388 int pthread_cond_timedwait_rel(pthread_cond_t *cond,
370 pthread_mutex_t *mutex, 389 pthread_mutex_t *mutex,
371 const struct timespec *reltime); 390 const struct timespec *reltime);
372 391
373 /** 392 /**
374 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually 393 * Defined for POSIX compatibility; pthread_cond_timedwait() is actually
375 * a macro calling pthread_cond_timedwait_abs(). 394 * a macro calling pthread_cond_timedwait_abs().
376 */ 395 */
377 #define pthread_cond_timedwait pthread_cond_timedwait_abs 396 #define pthread_cond_timedwait pthread_cond_timedwait_abs
378 397
398 /* Functions for rwlock handling. */
399
400 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
401 int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr,
402 int *pshared);
403 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared);
404 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
405
406 int pthread_rwlock_init(pthread_rwlock_t *rwlock,
407 const pthread_rwlockattr_t *attr);
408
409 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
410 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
411 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
412 const struct timespec *abstime);
413
414
415 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
416 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
417 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
418 const struct timespec *abstime);
419
420 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
421 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
379 422
380 /* Threads */ 423 /* Threads */
381 /** Thread entry function type. */ 424 /** Thread entry function type. */
382 typedef void *(*nc_thread_function)(void *p); 425 typedef void *(*nc_thread_function)(void *p);
383 /** Thread identifier type. */ 426 /** Thread identifier type. */
384 typedef struct __nc_basic_thread_data *pthread_t; 427 typedef struct __nc_basic_thread_data *pthread_t;
385 428
386 /** A structure representing thread attributes. */ 429 /** A structure representing thread attributes. */
387 typedef struct { 430 typedef struct {
388 int joinable; /**< 1 if the thread is joinable, 0 otherwise */ 431 int joinable; /**< 1 if the thread is joinable, 0 otherwise */
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 753
711 /** 754 /**
712 * @} End of PTHREAD group 755 * @} End of PTHREAD group
713 */ 756 */
714 757
715 #ifdef __cplusplus 758 #ifdef __cplusplus
716 } 759 }
717 #endif 760 #endif
718 761
719 #endif /* pthread.h */ 762 #endif /* pthread.h */
OLDNEW
« no previous file with comments | « src/untrusted/pthread/nc_rwlock.c ('k') | src/untrusted/pthread/pthread.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698