Lines Matching defs:mutex

5 #include <runtime/mutex.h>
10 // This mutex implementation is based on Ulrich Drepper's paper "Futexes
16 // The value of UNLOCKED must be 0 to match mutex.h and so that mutexes can
24 // On success, this will leave the mutex in the LOCKED_WITH_WAITERS state.
25 static zx_status_t lock_slow_path(zxr_mutex_t* mutex, zx_time_t abstime,
32 atomic_compare_exchange_strong(&mutex->futex, &old_state,
36 &mutex->futex, LOCKED_WITH_WAITERS, abstime);
41 // Try again to claim the mutex. On this try, we must set the
42 // mutex state to LOCKED_WITH_WAITERS rather than
44 // woken up when many threads are in the wait queue for the mutex.
46 if (atomic_compare_exchange_strong(&mutex->futex, &old_state,
53 zx_status_t zxr_mutex_trylock(zxr_mutex_t* mutex) {
55 if (atomic_compare_exchange_strong(&mutex->futex, &old_state,
62 zx_status_t __zxr_mutex_timedlock(zxr_mutex_t* mutex, zx_time_t abstime) {
63 // Try to claim the mutex. This compare-and-swap executes the full
64 // memory barrier that locking a mutex is required to execute.
66 if (atomic_compare_exchange_strong(&mutex->futex, &old_state,
70 return lock_slow_path(mutex, abstime, old_state);
73 void zxr_mutex_lock(zxr_mutex_t* mutex) {
74 zx_status_t status = __zxr_mutex_timedlock(mutex, ZX_TIME_INFINITE);
79 void zxr_mutex_lock_with_waiter(zxr_mutex_t* mutex) {
81 if (atomic_compare_exchange_strong(&mutex->futex, &old_state,
85 zx_status_t status = lock_slow_path(mutex, ZX_TIME_INFINITE, old_state);
90 void zxr_mutex_unlock(zxr_mutex_t* mutex) {
91 // Attempt to release the mutex. This atomic swap executes the full
92 // memory barrier that unlocking a mutex is required to execute.
93 int old_state = atomic_exchange(&mutex->futex, UNLOCKED);
100 zx_status_t status = _zx_futex_wake(&mutex->futex, 1);
108 // Either the mutex was unlocked (in which case the unlock call
109 // was invalid), or the mutex was in an invalid state.