diff options
author | davidxu <davidxu@FreeBSD.org> | 2008-04-01 00:21:49 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2008-04-01 00:21:49 +0000 |
commit | 664ef9f3652cb679f74786c2681b1a78d1385da0 (patch) | |
tree | 98aaddb0eab03c91c63ab6db4517fe1e535ff3e4 /lib/libthr | |
parent | f69578dd1e2f1de1b7e84b05f1b918f13bc544b1 (diff) | |
download | FreeBSD-src-664ef9f3652cb679f74786c2681b1a78d1385da0.zip FreeBSD-src-664ef9f3652cb679f74786c2681b1a78d1385da0.tar.gz |
return EAGAIN early rather than running bunch of code later, micro optimize
static branch prediction.
Diffstat (limited to 'lib/libthr')
-rw-r--r-- | lib/libthr/thread/thr_rwlock.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c index e4c3eae..0380072 100644 --- a/lib/libthr/thread/thr_rwlock.c +++ b/lib/libthr/thread/thr_rwlock.c @@ -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))) |