*
*/
-#define __likely(cond) __builtin_expect(!!(cond), 1)
-#define __unlikely(cond) __builtin_expect(!!(cond), 0)
-
#define RWLOCKATTR_DEFAULT 0
#define RWLOCKATTR_SHARED_MASK 0x0010
return EINVAL;
pthread_mutex_lock(&rwlock->lock);
- if (__unlikely(!read_precondition(rwlock, __get_thread()->tid)))
+ if (__predict_false(!read_precondition(rwlock, __get_thread()->tid)))
ret = EBUSY;
else
rwlock->numLocks ++;
pthread_mutex_lock(&rwlock->lock);
int tid = __get_thread()->tid;
- if (__unlikely(!read_precondition(rwlock, tid))) {
+ if (__predict_false(!read_precondition(rwlock, tid))) {
rwlock->pendingReaders += 1;
do {
ret = pthread_cond_timedwait(&rwlock->cond, &rwlock->lock, abs_timeout);
pthread_mutex_lock(&rwlock->lock);
int tid = __get_thread()->tid;
- if (__unlikely(!write_precondition(rwlock, tid))) {
+ if (__predict_false(!write_precondition(rwlock, tid))) {
ret = EBUSY;
} else {
rwlock->numLocks ++;
pthread_mutex_lock(&rwlock->lock);
int tid = __get_thread()->tid;
- if (__unlikely(!write_precondition(rwlock, tid))) {
+ if (__predict_false(!write_precondition(rwlock, tid))) {
/* If we can't read yet, wait until the rwlock is unlocked
* and try again. Increment pendingReaders to get the
* cond broadcast when that happens.
/* the maximum value of overrun counters */
#define DELAYTIMER_MAX 0x7fffffff
-#define __likely(x) __builtin_expect(!!(x),1)
-#define __unlikely(x) __builtin_expect(!!(x),0)
-
typedef struct thr_timer thr_timer_t;
typedef struct thr_timer_table thr_timer_table_t;
int timer_create(clockid_t clock_id, struct sigevent* evp, timer_t* timer_id) {
// If not a SIGEV_THREAD timer, the kernel can handle it without our help.
- if (__likely(evp == NULL || evp->sigev_notify != SIGEV_THREAD)) {
+ if (__predict_true(evp == NULL || evp->sigev_notify != SIGEV_THREAD)) {
return __timer_create(clock_id, evp, timer_id);
}
int
timer_delete( timer_t id )
{
- if ( __likely(!TIMER_ID_IS_WRAPPED(id)) )
+ if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) )
return __timer_delete( id );
else
{
return -1;
}
- if ( __likely(!TIMER_ID_IS_WRAPPED(id)) ) {
+ if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) ) {
return __timer_gettime( id, ospec );
} else {
thr_timer_t* timer = thr_timer_from_id(id);
return -1;
}
- if ( __likely(!TIMER_ID_IS_WRAPPED(id)) ) {
+ if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) ) {
return __timer_settime( id, flags, spec, ospec );
} else {
thr_timer_t* timer = thr_timer_from_id(id);
int
timer_getoverrun(timer_t id)
{
- if ( __likely(!TIMER_ID_IS_WRAPPED(id)) ) {
+ if ( __predict_true(!TIMER_ID_IS_WRAPPED(id)) ) {
return __timer_getoverrun( id );
} else {
thr_timer_t* timer = thr_timer_from_id(id);
return __futex_syscall4(ftx, pshared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, val, timeout);
}
-#define __likely(cond) __builtin_expect(!!(cond), 1)
-#define __unlikely(cond) __builtin_expect(!!(cond), 0)
-
-void*
-__get_stack_base(int *p_stack_size)
-{
- pthread_internal_t* thread = __get_thread();
-
- *p_stack_size = thread->attr.stack_size;
- return thread->attr.stack_base;
-}
-
-
/* CAVEAT: our implementation of pthread_cleanup_push/pop doesn't support C++ exceptions
* and thread cancelation
*/
if (mutex == NULL)
return EINVAL;
- if (__likely(attr == NULL)) {
+ if (__predict_true(attr == NULL)) {
mutex->value = MUTEX_TYPE_BITS_NORMAL;
return 0;
}
for (;;) {
/* increment counter, overflow was already checked */
int newval = mvalue + MUTEX_COUNTER_BITS_ONE;
- if (__likely(__bionic_cmpxchg(mvalue, newval, &mutex->value) == 0)) {
+ if (__predict_true(__bionic_cmpxchg(mvalue, newval, &mutex->value) == 0)) {
/* mutex is still locked, not need for a memory barrier */
return 0;
}
{
int mvalue, mtype, tid, shared;
- if (__unlikely(mutex == NULL))
+ if (__predict_false(mutex == NULL))
return EINVAL;
mvalue = mutex->value;
shared = (mvalue & MUTEX_SHARED_MASK);
/* Handle normal case first */
- if ( __likely(mtype == MUTEX_TYPE_BITS_NORMAL) ) {
+ if ( __predict_true(mtype == MUTEX_TYPE_BITS_NORMAL) ) {
_normal_lock(mutex, shared);
return 0;
}
* implement it to get rid of the explicit memory
* barrier below.
*/
- if (__unlikely(__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0)) {
+ if (__predict_false(__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0)) {
mvalue = mutex->value;
continue;
}
* 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 (__unlikely(__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0)) {
+ if (__predict_false(__bionic_cmpxchg(mvalue, newval, &mutex->value) != 0)) {
mvalue = mutex->value;
continue;
}
{
int mvalue, mtype, tid, shared;
- if (__unlikely(mutex == NULL))
+ if (__predict_false(mutex == NULL))
return EINVAL;
mvalue = mutex->value;
shared = (mvalue & MUTEX_SHARED_MASK);
/* Handle common case first */
- if (__likely(mtype == MUTEX_TYPE_BITS_NORMAL)) {
+ if (__predict_true(mtype == MUTEX_TYPE_BITS_NORMAL)) {
_normal_unlock(mutex, shared);
return 0;
}
if (!MUTEX_COUNTER_BITS_IS_ZERO(mvalue)) {
for (;;) {
int newval = mvalue - MUTEX_COUNTER_BITS_ONE;
- if (__likely(__bionic_cmpxchg(mvalue, newval, &mutex->value) == 0)) {
+ if (__predict_true(__bionic_cmpxchg(mvalue, newval, &mutex->value) == 0)) {
/* success: we still own the mutex, so no memory barrier */
return 0;
}
{
int mvalue, mtype, tid, shared;
- if (__unlikely(mutex == NULL))
+ if (__predict_false(mutex == NULL))
return EINVAL;
mvalue = mutex->value;
shared = (mvalue & MUTEX_SHARED_MASK);
/* Handle common case first */
- if ( __likely(mtype == MUTEX_TYPE_BITS_NORMAL) )
+ if ( __predict_true(mtype == MUTEX_TYPE_BITS_NORMAL) )
{
if (__bionic_cmpxchg(shared|MUTEX_STATE_BITS_UNLOCKED,
shared|MUTEX_STATE_BITS_LOCKED_UNCONTENDED,
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)) {
+ if (__predict_true(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) {
ANDROID_MEMBAR_FULL();
return 0;
}
/* compute absolute expiration time */
__timespec_to_relative_msec(&abstime, msecs, clock);
- if (__unlikely(mutex == NULL))
+ if (__predict_false(mutex == NULL))
return EINVAL;
mvalue = mutex->value;
shared = (mvalue & MUTEX_SHARED_MASK);
/* Handle common case first */
- if ( __likely(mtype == MUTEX_TYPE_BITS_NORMAL) )
+ 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;
/* 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)) {
+ if (__predict_true(__bionic_cmpxchg(mtype, mvalue, &mutex->value) == 0)) {
ANDROID_MEMBAR_FULL();
return 0;
}
{
long flags;
- if (__unlikely(cond == NULL))
+ if (__predict_false(cond == NULL))
return EINVAL;
flags = (cond->value & ~COND_COUNTER_MASK);
* stores performed by the initialization function are observable on
* this CPU after we exit.
*/
- if (__likely((*ocptr & ONCE_COMPLETED) != 0)) {
+ if (__predict_true((*ocptr & ONCE_COMPLETED) != 0)) {
ANDROID_MEMBAR_FULL();
return 0;
}