return EAGAIN early rather than running bunch of code later, micro optimize

static branch prediction.
This commit is contained in:
David Xu 2008-04-01 00:21:49 +00:00
parent e955d4fd10
commit f5bc4f9930
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=177818

View File

@ -158,7 +158,7 @@ rwlock_tryrdlock(struct pthread_rwlock *prwlock, int prefer_reader)
wrflags = RWLOCK_WRITE_OWNER | RWLOCK_WRITE_WAITERS;
state = prwlock->state;
while (!(state & wrflags)) {
if (RWLOCK_READER_COUNT(state) == RWLOCK_MAX_READERS)
if (__predict_false(RWLOCK_READER_COUNT(state) == RWLOCK_MAX_READERS))
return (EAGAIN);
if (atomic_cmpset_acq_32(&prwlock->state, state, state + 1))
return (0);
@ -200,6 +200,8 @@ rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime)
curthread->rdlock_count++;
return (ret);
}
if (__predict_false(ret == EAGAIN))
return (ret);
if (__predict_false(abstime &&
(abstime->tv_nsec >= 1000000000 || abstime->tv_nsec < 0)))