Lines Matching defs:mutex

36 	CONTENDED = 2,	/* threads waiting for this mutex */
51 pthread_mutex_t mutex;
53 mutex = calloc(1, sizeof(*mutex));
54 if (mutex == NULL)
58 mutex->type = PTHREAD_MUTEX_DEFAULT;
59 mutex->prioceiling = -1;
61 mutex->type = (*attr)->ma_type;
62 mutex->prioceiling = (*attr)->ma_protocol ==
65 *mutexp = mutex;
74 pthread_mutex_t mutex;
79 mutex = *mutexp;
80 if (mutex) {
81 if (mutex->lock != UNLOCKED) {
82 #define MSG "pthread_mutex_destroy on mutex with waiters!\n"
87 free((void *)mutex);
96 _rthread_mutex_trylock(pthread_mutex_t mutex, int trywait,
101 if (atomic_cas_uint(&mutex->lock, UNLOCKED, LOCKED) == UNLOCKED) {
103 mutex->owner = self;
107 if (mutex->owner == self) {
108 int type = mutex->type;
120 while (_twait(&mutex->type, type, CLOCK_REALTIME,
125 if (mutex->count == INT_MAX)
127 mutex->count++;
140 pthread_mutex_t mutex;
148 * If the mutex is statically initialized, perform the dynamic
150 * pthread_mutex_lock() to perform the mutex init when *mutexp
162 mutex = *mutexp;
164 (timed ? "timed" : (trywait ? "try" : "")), (void *)mutex,
165 (void *)mutex->owner);
167 error = _rthread_mutex_trylock(mutex, trywait, abs);
173 if (mutex->lock == UNLOCKED)
179 lock = atomic_cas_uint(&mutex->lock, UNLOCKED, LOCKED);
182 mutex->owner = self;
187 /* Indicate that we're waiting on this mutex. */
188 lock = atomic_swap_uint(&mutex->lock, CONTENDED);
192 error = _twait(&mutex->lock, CONTENDED, CLOCK_REALTIME, abs);
199 lock = atomic_swap_uint(&mutex->lock, CONTENDED);
203 mutex->owner = self;
230 pthread_mutex_t mutex;
244 mutex = *mutexp;
245 _rthread_debug(5, "%p: mutex_unlock %p (%p)\n", self, (void *)mutex,
246 (void *)mutex->owner);
248 if (mutex->owner != self) {
249 _rthread_debug(5, "%p: different owner %p (%p)\n", self, (void *)mutex,
250 (void *)mutex->owner);
251 if (mutex->type == PTHREAD_MUTEX_ERRORCHECK ||
252 mutex->type == PTHREAD_MUTEX_RECURSIVE) {
256 * For mutex type NORMAL our undefined behavior for
257 * unlocking an unlocked mutex is to succeed without
261 if (mutex->owner == NULL &&
262 mutex->type == PTHREAD_MUTEX_NORMAL)
270 if (mutex->type == PTHREAD_MUTEX_RECURSIVE) {
271 if (mutex->count > 0) {
272 mutex->count--;
277 mutex->owner = NULL;
279 if (atomic_dec_int_nv(&mutex->lock) != UNLOCKED) {
280 mutex->lock = UNLOCKED;
281 _wake(&mutex->lock, 1);