/* This function is used by pthread_cond_broadcast and * pthread_cond_signal to atomically decrement the counter * then wake-up 'counter' threads. */ static int __pthread_cond_pulse(pthread_cond_t *cond, int counter) { long flags; if (__unlikely(cond == NULL)) return EINVAL; flags = (cond->value & ~COND_COUNTER_MASK); for (;;) { long oldval = cond->value; long newval = ((oldval - COND_COUNTER_INCREMENT) & COND_COUNTER_MASK) | flags; if (__bionic_cmpxchg(oldval, newval, &cond->value) == 0) break; } /* * Ensure that all memory accesses previously made by this thread are * visible to the woken thread(s). On the other side, the "wait" * code will issue any necessary barriers when locking the mutex. * * This may not strictly be necessary -- if the caller follows * recommended practice and holds the mutex before signaling the cond * var, the mutex ops will provide correct semantics. If they don't * hold the mutex, they're subject to race conditions anyway. */ ANDROID_MEMBAR_FULL(); __futex_wake_ex(&cond->value, COND_IS_SHARED(cond), counter); return 0; }
/* * Lock a non-recursive mutex. * * As noted above, there are three states: * 0 (unlocked, no contention) * 1 (locked, no contention) * 2 (locked, contention) * * Non-recursive mutexes don't use the thread-id or counter fields, and the * "type" value is zero, so the only bits that will be set are the ones in * the lock state field. */ static __inline__ void _normal_lock(pthread_mutex_t* mutex, int shared) { /* convenience shortcuts */ const int unlocked = shared | MUTEX_STATE_BITS_UNLOCKED; const int locked_uncontended = shared | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; /* * The common case is an unlocked mutex, so we begin by trying to * change the lock's state from 0 (UNLOCKED) to 1 (LOCKED). * __bionic_cmpxchg() returns 0 if it made the swap successfully. * If the result is nonzero, this lock is already held by another thread. */ if (__bionic_cmpxchg(unlocked, locked_uncontended, &mutex->value) != 0) { const int locked_contended = shared | MUTEX_STATE_BITS_LOCKED_CONTENDED; /* * We want to go to sleep until the mutex is available, which * requires promoting it to state 2 (CONTENDED). We need to * swap in the new state value and then wait until somebody wakes us up. * * __bionic_swap() returns the previous value. We swap 2 in and * see if we got zero back; if so, we have acquired the lock. If * not, another thread still holds the lock and we wait again. * * The second argument to the __futex_wait() call is compared * against the current value. If it doesn't match, __futex_wait() * returns immediately (otherwise, it sleeps for a time specified * by the third argument; 0 means sleep forever). This ensures * that the mutex is in state 2 when we go to sleep on it, which * guarantees a wake-up call. */ while (__bionic_swap(locked_contended, &mutex->value) != unlocked) __futex_wait_ex(&mutex->value, shared, locked_contended, 0); } ANDROID_MEMBAR_FULL(); }
int __system_property_read(const prop_info *pi, char *name, char *value) { unsigned serial, len; if (__predict_false(compat_mode)) { return __system_property_read_compat(pi, name, value); } for(;;) { serial = pi->serial; while(SERIAL_DIRTY(serial)) { __futex_wait((volatile void *)&pi->serial, serial, NULL); serial = pi->serial; } len = SERIAL_VALUE_LEN(serial); memcpy(value, pi->value, len + 1); ANDROID_MEMBAR_FULL(); if(serial == pi->serial) { if(name != 0) { strcpy(name, pi->name); } return len; } } }
prop_bt(const char *name, const uint8_t name_length) { this->namelen = name_length; memcpy(this->name, name, name_length); this->name[name_length] = '\0'; ANDROID_MEMBAR_FULL(); // TODO: Instead use a release store // for subsequent pointer assignment. }
// This function is used by pthread_cond_broadcast and // pthread_cond_signal to atomically decrement the counter // then wake up 'counter' threads. static int __pthread_cond_pulse(pthread_cond_t* cond, int counter) { if (__predict_false(cond == NULL)) { return EINVAL; } long flags = (cond->value & ~COND_COUNTER_MASK); while (true) { long old_value = cond->value; long new_value = ((old_value - COND_COUNTER_INCREMENT) & COND_COUNTER_MASK) | flags; if (__bionic_cmpxchg(old_value, new_value, &cond->value) == 0) { break; } } // Ensure that all memory accesses previously made by this thread are // visible to the woken thread(s). On the other side, the "wait" // code will issue any necessary barriers when locking the mutex. // // This may not strictly be necessary -- if the caller follows // recommended practice and holds the mutex before signaling the cond // var, the mutex ops will provide correct semantics. If they don't // hold the mutex, they're subject to race conditions anyway. ANDROID_MEMBAR_FULL(); __futex_wake_ex(&cond->value, COND_IS_SHARED(cond), counter); return 0; }
prop_info(const char *name, const uint8_t namelen, const char *value, const uint8_t valuelen) { memcpy(this->name, name, namelen); this->name[namelen] = '\0'; this->serial = (valuelen << 24); memcpy(this->value, value, valuelen); this->value[valuelen] = '\0'; ANDROID_MEMBAR_FULL(); }
__LIBC_HIDDEN__ int pthread_mutex_trylock_impl(pthread_mutex_t *mutex) { int mvalue, mtype, tid, shared; if (__unlikely(mutex == NULL)) return EINVAL; mvalue = mutex->value; mtype = (mvalue & MUTEX_TYPE_MASK); shared = (mvalue & MUTEX_SHARED_MASK); /* Handle common case first */ if ( __likely(mtype == MUTEX_TYPE_BITS_NORMAL) ) { if (__bionic_cmpxchg(shared|MUTEX_STATE_BITS_UNLOCKED, shared|MUTEX_STATE_BITS_LOCKED_UNCONTENDED, &mutex->value) == 0) { ANDROID_MEMBAR_FULL(); return 0; } return EBUSY; } /* Do we already own this recursive or error-check mutex ? */ tid = __get_thread()->tid; if ( tid == MUTEX_OWNER_FROM_BITS(mvalue) ) return _recursive_increment(mutex, mvalue, mtype); /* Same as pthread_mutex_lock, except that we don't want to wait, and * the only operation that can succeed is a single cmpxchg to acquire the * lock if it is released / not owned by anyone. No need for a complex loop. */ mtype |= shared | MUTEX_STATE_BITS_UNLOCKED; mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; if (__likely(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) { ANDROID_MEMBAR_FULL(); return 0; } return EBUSY; }
__LIBC_HIDDEN__ int pthread_mutex_unlock_impl(pthread_mutex_t *mutex) { int mvalue, mtype, tid, shared; if (__unlikely(mutex == NULL)) return EINVAL; mvalue = mutex->value; mtype = (mvalue & MUTEX_TYPE_MASK); shared = (mvalue & MUTEX_SHARED_MASK); /* Handle common case first */ if (__likely(mtype == MUTEX_TYPE_BITS_NORMAL)) { _normal_unlock(mutex, shared); return 0; } /* Do we already own this recursive or error-check mutex ? */ tid = __get_thread()->tid; if ( tid != MUTEX_OWNER_FROM_BITS(mvalue) ) return EPERM; /* If the counter is > 0, we can simply decrement it atomically. * Since other threads can mutate the lower state bits (and only the * lower state bits), use a cmpxchg to do it. */ if (!MUTEX_COUNTER_BITS_IS_ZERO(mvalue)) { for (;;) { int newval = mvalue - MUTEX_COUNTER_BITS_ONE; if (__likely(__bionic_cmpxchg(mvalue, newval, &mutex->value) == 0)) { /* success: we still own the mutex, so no memory barrier */ return 0; } /* the value changed, so reload and loop */ mvalue = mutex->value; } } /* the counter is 0, so we're going to unlock the mutex by resetting * its value to 'unlocked'. We need to perform a swap in order * to read the current state, which will be 2 if there are waiters * to awake. * * TODO: Change this to __bionic_swap_release when we implement it * to get rid of the explicit memory barrier below. */ ANDROID_MEMBAR_FULL(); /* RELEASE BARRIER */ mvalue = __bionic_swap(mtype | shared | MUTEX_STATE_BITS_UNLOCKED, &mutex->value); /* Wake one waiting thread, if any */ if (MUTEX_STATE_BITS_IS_LOCKED_CONTENDED(mvalue)) { __futex_wake_ex(&mutex->value, shared, 1); } return 0; }
prop_info(const char *name, const uint8_t namelen, const char *value, const uint8_t valuelen) { memcpy(this->name, name, namelen); this->name[namelen] = '\0'; atomic_init(&this->serial, valuelen << 24); memcpy(this->value, value, valuelen); this->value[valuelen] = '\0'; ANDROID_MEMBAR_FULL(); // TODO: Instead use a release store // for subsequent point assignment. }
int __system_property_update(prop_info *pi, const char *value, unsigned int len) { prop_area *pa = __system_property_area__; if (len >= PROP_VALUE_MAX) return -1; pi->serial = pi->serial | 1; ANDROID_MEMBAR_FULL(); memcpy(pi->value, value, len + 1); ANDROID_MEMBAR_FULL(); pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff); __futex_wake(&pi->serial, INT32_MAX); pa->serial++; __futex_wake(&pa->serial, INT32_MAX); return 0; }
extern "C" int __cxa_guard_acquire(_guard_t* gv) { // 0 -> pending, return 1 // pending -> waiting, wait and return 0 // waiting: untouched, wait and return 0 // ready: untouched, return 0 retry: if (__atomic_cmpxchg(0, pending, &gv->state) == 0) { ANDROID_MEMBAR_FULL(); return 1; } __atomic_cmpxchg(pending, waiting, &gv->state); // Indicate there is a waiter __futex_wait(&gv->state, waiting, NULL); if (gv->state != ready) // __cxa_guard_abort was called, let every thread try since there is no return code for this condition goto retry; ANDROID_MEMBAR_FULL(); return 0; }
extern "C" void __cxa_guard_release(_guard_t* gv) { // pending -> ready // waiting -> ready, and wake ANDROID_MEMBAR_FULL(); if (__atomic_cmpxchg(pending, ready, &gv->state) == 0) { return; } gv->state = ready; __futex_wake(&gv->state, 0x7fffffff); }
/* * Release a non-recursive mutex. The caller is responsible for determining * that we are in fact the owner of this lock. */ static __inline__ void _normal_unlock(pthread_mutex_t* mutex, int shared) { ANDROID_MEMBAR_FULL(); /* * The mutex state will be 1 or (rarely) 2. We use an atomic decrement * to release the lock. __bionic_atomic_dec() returns the previous value; * if it wasn't 1 we have to do some additional work. */ if (__bionic_atomic_dec(&mutex->value) != (shared|MUTEX_STATE_BITS_LOCKED_UNCONTENDED)) { /* * Start by releasing the lock. The decrement changed it from * "contended lock" to "uncontended lock", which means we still * hold it, and anybody who tries to sneak in will push it back * to state 2. * * Once we set it to zero the lock is up for grabs. We follow * this with a __futex_wake() to ensure that one of the waiting * threads has a chance to grab it. * * This doesn't cause a race with the swap/wait pair in * _normal_lock(), because the __futex_wait() call there will * return immediately if the mutex value isn't 2. */ mutex->value = shared; /* * Wake up one waiting thread. We don't know which thread will be * woken or when it'll start executing -- futexes make no guarantees * here. There may not even be a thread waiting. * * The newly-woken thread will replace the 0 we just set above * with 2, which means that when it eventually releases the mutex * it will also call FUTEX_WAKE. This results in one extra wake * call whenever a lock is contended, but lets us avoid forgetting * anyone without requiring us to track the number of sleepers. * * It's possible for another thread to sneak in and grab the lock * between the zero assignment above and the wake call below. If * the new thread is "slow" and holds the lock for a while, we'll * wake up a sleeper, which will swap in a 2 and then go back to * sleep since the lock is still held. If the new thread is "fast", * running to completion before we call wake, the thread we * eventually wake will find an unlocked mutex and will execute. * Either way we have correct behavior and nobody is orphaned on * the wait queue. */ __futex_wake_ex(&mutex->value, shared, 1); } }
static int __pthread_mutex_timedlock(pthread_mutex_t* mutex, const timespec* abs_timeout, clockid_t clock) { timespec ts; int mvalue = mutex->value; int mtype = (mvalue & MUTEX_TYPE_MASK); int shared = (mvalue & MUTEX_SHARED_MASK); // Handle common case first. if (__predict_true(mtype == MUTEX_TYPE_BITS_NORMAL)) { const int unlocked = shared | MUTEX_STATE_BITS_UNLOCKED; const int locked_uncontended = shared | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; const int locked_contended = shared | MUTEX_STATE_BITS_LOCKED_CONTENDED; // Fast path for uncontended lock. Note: MUTEX_TYPE_BITS_NORMAL is 0. if (__bionic_cmpxchg(unlocked, locked_uncontended, &mutex->value) == 0) { ANDROID_MEMBAR_FULL(); return 0; } // Loop while needed. while (__bionic_swap(locked_contended, &mutex->value) != unlocked) { if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) { return ETIMEDOUT; } __futex_wait_ex(&mutex->value, shared, locked_contended, &ts); } ANDROID_MEMBAR_FULL(); return 0; } // Do we already own this recursive or error-check mutex? pid_t tid = __get_thread()->tid; if (tid == MUTEX_OWNER_FROM_BITS(mvalue)) { return _recursive_increment(mutex, mvalue, mtype); } // The following implements the same loop as pthread_mutex_lock_impl // but adds checks to ensure that the operation never exceeds the // absolute expiration time. mtype |= shared; // First try a quick lock. if (mvalue == mtype) { mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; if (__predict_true(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) { ANDROID_MEMBAR_FULL(); return 0; } mvalue = mutex->value; } while (true) { // If the value is 'unlocked', try to acquire it directly. // NOTE: put state to 2 since we know there is contention. if (mvalue == mtype) { // Unlocked. mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_CONTENDED; if (__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0) { ANDROID_MEMBAR_FULL(); return 0; } // The value changed before we could lock it. We need to check // the time to avoid livelocks, reload the value, then loop again. if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) { return ETIMEDOUT; } mvalue = mutex->value; continue; } // The value is locked. If 'uncontended', try to switch its state // to 'contented' to ensure we get woken up later. if (MUTEX_STATE_BITS_IS_LOCKED_UNCONTENDED(mvalue)) { int newval = MUTEX_STATE_BITS_FLIP_CONTENTION(mvalue); if (__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0) { // This failed because the value changed, reload it. mvalue = mutex->value; } else { // This succeeded, update mvalue. mvalue = newval; } } // Check time and update 'ts'. if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) { return ETIMEDOUT; } // Only wait to be woken up if the state is '2', otherwise we'll // simply loop right now. This can happen when the second cmpxchg // in our loop failed because the mutex was unlocked by another thread. if (MUTEX_STATE_BITS_IS_LOCKED_CONTENDED(mvalue)) { if (__futex_wait_ex(&mutex->value, shared, mvalue, &ts) == -ETIMEDOUT) { return ETIMEDOUT; } mvalue = mutex->value; } } /* NOTREACHED */ }
__LIBC_HIDDEN__ int pthread_mutex_lock_impl(pthread_mutex_t *mutex) { int mvalue, mtype, tid, shared; mvalue = mutex->value; mtype = (mvalue & MUTEX_TYPE_MASK); shared = (mvalue & MUTEX_SHARED_MASK); /* Handle normal case first */ if ( __predict_true(mtype == MUTEX_TYPE_BITS_NORMAL) ) { _normal_lock(mutex, shared); return 0; } /* Do we already own this recursive or error-check mutex ? */ tid = __get_thread()->tid; if ( tid == MUTEX_OWNER_FROM_BITS(mvalue) ) return _recursive_increment(mutex, mvalue, mtype); /* Add in shared state to avoid extra 'or' operations below */ mtype |= shared; /* First, if the mutex is unlocked, try to quickly acquire it. * In the optimistic case where this works, set the state to 1 to * indicate locked with no contention */ if (mvalue == mtype) { int newval = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; if (__bionic_cmpxchg(mvalue, newval, &mutex->value) == 0) { ANDROID_MEMBAR_FULL(); return 0; } /* argh, the value changed, reload before entering the loop */ mvalue = mutex->value; } for (;;) { int newval; /* if the mutex is unlocked, its value should be 'mtype' and * we try to acquire it by setting its owner and state atomically. * NOTE: We put the state to 2 since we _know_ there is contention * when we are in this loop. This ensures all waiters will be * unlocked. */ if (mvalue == mtype) { newval = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_CONTENDED; /* TODO: Change this to __bionic_cmpxchg_acquire when we * implement it to get rid of the explicit memory * barrier below. */ if (__predict_false(__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0)) { mvalue = mutex->value; continue; } ANDROID_MEMBAR_FULL(); return 0; } /* the mutex is already locked by another thread, if its state is 1 * we will change it to 2 to indicate contention. */ if (MUTEX_STATE_BITS_IS_LOCKED_UNCONTENDED(mvalue)) { newval = MUTEX_STATE_BITS_FLIP_CONTENTION(mvalue); /* locked state 1 => state 2 */ if (__predict_false(__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0)) { mvalue = mutex->value; continue; } mvalue = newval; } /* wait until the mutex is unlocked */ __futex_wait_ex(&mutex->value, shared, mvalue, NULL); mvalue = mutex->value; } /* NOTREACHED */ }
prop_bt(const char *name, const uint8_t name_length) { this->namelen = name_length; memcpy(this->name, name, name_length); this->name[name_length] = '\0'; ANDROID_MEMBAR_FULL(); }
extern "C" void __cxa_guard_abort(_guard_t* gv) { ANDROID_MEMBAR_FULL(); gv->state= 0; __futex_wake(&gv->state, 0x7fffffff); }
/* NOTE: this implementation doesn't support a init function that throws a C++ exception * or calls fork() */ int pthread_once( pthread_once_t* once_control, void (*init_routine)(void) ) { volatile pthread_once_t* ocptr = once_control; /* PTHREAD_ONCE_INIT is 0, we use the following bit flags * * bit 0 set -> initialization is under way * bit 1 set -> initialization is complete */ #define ONCE_INITIALIZING (1 << 0) #define ONCE_COMPLETED (1 << 1) /* First check if the once is already initialized. This will be the common * case and we want to make this as fast as possible. Note that this still * requires a load_acquire operation here to ensure that all the * stores performed by the initialization function are observable on * this CPU after we exit. */ if (__likely((*ocptr & ONCE_COMPLETED) != 0)) { ANDROID_MEMBAR_FULL(); return 0; } for (;;) { /* Try to atomically set the INITIALIZING flag. * This requires a cmpxchg loop, and we may need * to exit prematurely if we detect that * COMPLETED is now set. */ int32_t oldval, newval; do { oldval = *ocptr; if ((oldval & ONCE_COMPLETED) != 0) break; newval = oldval | ONCE_INITIALIZING; } while (__bionic_cmpxchg(oldval, newval, ocptr) != 0); if ((oldval & ONCE_COMPLETED) != 0) { /* We detected that COMPLETED was set while in our loop */ ANDROID_MEMBAR_FULL(); return 0; } if ((oldval & ONCE_INITIALIZING) == 0) { /* We got there first, we can jump out of the loop to * handle the initialization */ break; } /* Another thread is running the initialization and hasn't completed * yet, so wait for it, then try again. */ __futex_wait_ex(ocptr, 0, oldval, NULL); } /* call the initialization function. */ (*init_routine)(); /* Do a store_release indicating that initialization is complete */ ANDROID_MEMBAR_FULL(); *ocptr = ONCE_COMPLETED; /* Wake up any waiters, if any */ __futex_wake_ex(ocptr, 0, INT_MAX); return 0; }
__LIBC_HIDDEN__ int pthread_mutex_lock_timeout_np_impl(pthread_mutex_t *mutex, unsigned msecs) { clockid_t clock = CLOCK_MONOTONIC; struct timespec abstime; struct timespec ts; int mvalue, mtype, tid, shared; /* compute absolute expiration time */ __timespec_to_relative_msec(&abstime, msecs, clock); if (__unlikely(mutex == NULL)) return EINVAL; mvalue = mutex->value; mtype = (mvalue & MUTEX_TYPE_MASK); shared = (mvalue & MUTEX_SHARED_MASK); /* Handle common case first */ if ( __likely(mtype == MUTEX_TYPE_BITS_NORMAL) ) { const int unlocked = shared | MUTEX_STATE_BITS_UNLOCKED; const int locked_uncontended = shared | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; const int locked_contended = shared | MUTEX_STATE_BITS_LOCKED_CONTENDED; /* fast path for uncontended lock. Note: MUTEX_TYPE_BITS_NORMAL is 0 */ if (__bionic_cmpxchg(unlocked, locked_uncontended, &mutex->value) == 0) { ANDROID_MEMBAR_FULL(); return 0; } /* loop while needed */ while (__bionic_swap(locked_contended, &mutex->value) != unlocked) { if (__timespec_to_absolute(&ts, &abstime, clock) < 0) return EBUSY; __futex_wait_ex(&mutex->value, shared, locked_contended, &ts); } ANDROID_MEMBAR_FULL(); return 0; } /* Do we already own this recursive or error-check mutex ? */ tid = __get_thread()->tid; if ( tid == MUTEX_OWNER_FROM_BITS(mvalue) ) return _recursive_increment(mutex, mvalue, mtype); /* the following implements the same loop than pthread_mutex_lock_impl * but adds checks to ensure that the operation never exceeds the * absolute expiration time. */ mtype |= shared; /* first try a quick lock */ if (mvalue == mtype) { mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_UNCONTENDED; if (__likely(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) { ANDROID_MEMBAR_FULL(); return 0; } mvalue = mutex->value; } for (;;) { struct timespec ts; /* if the value is 'unlocked', try to acquire it directly */ /* NOTE: put state to 2 since we know there is contention */ if (mvalue == mtype) { /* unlocked */ mvalue = MUTEX_OWNER_TO_BITS(tid) | mtype | MUTEX_STATE_BITS_LOCKED_CONTENDED; if (__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0) { ANDROID_MEMBAR_FULL(); return 0; } /* the value changed before we could lock it. We need to check * the time to avoid livelocks, reload the value, then loop again. */ if (__timespec_to_absolute(&ts, &abstime, clock) < 0) return EBUSY; mvalue = mutex->value; continue; } /* The value is locked. If 'uncontended', try to switch its state * to 'contented' to ensure we get woken up later. */ if (MUTEX_STATE_BITS_IS_LOCKED_UNCONTENDED(mvalue)) { int newval = MUTEX_STATE_BITS_FLIP_CONTENTION(mvalue); if (__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0) { /* this failed because the value changed, reload it */ mvalue = mutex->value; } else { /* this succeeded, update mvalue */ mvalue = newval; } } /* check time and update 'ts' */ if (__timespec_to_absolute(&ts, &abstime, clock) < 0) return EBUSY; /* Only wait to be woken up if the state is '2', otherwise we'll * simply loop right now. This can happen when the second cmpxchg * in our loop failed because the mutex was unlocked by another * thread. */ if (MUTEX_STATE_BITS_IS_LOCKED_CONTENDED(mvalue)) { if (__futex_wait_ex(&mutex->value, shared, mvalue, &ts) == ETIMEDOUT) { return EBUSY; } mvalue = mutex->value; } } /* NOTREACHED */ }