diff options
author | davidxu <davidxu@FreeBSD.org> | 2010-01-05 03:39:31 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2010-01-05 03:39:31 +0000 |
commit | 8ea6a66616580dbd388bcbc17ab0def79d86724f (patch) | |
tree | 28440e4c713dc6740a5f652375ba1fbbca0b9edc /lib | |
parent | 87c8a1faf252e6bbed958df4fbcbfae972bf04d9 (diff) | |
download | FreeBSD-src-8ea6a66616580dbd388bcbc17ab0def79d86724f.zip FreeBSD-src-8ea6a66616580dbd388bcbc17ab0def79d86724f.tar.gz |
Don't check has_waiters twice, inline some small functions.
performance result on my machine:
mutex Elapsed: 902115 us; per iteration: 90 ns.
semaphore Elapsed: 958780 us; per iteration: 95 ns.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/sem_new.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c index dac5381..844be28 100644 --- a/lib/libc/gen/sem_new.c +++ b/lib/libc/gen/sem_new.c @@ -331,7 +331,7 @@ _libc_sem_getvalue(sem_t * __restrict sem, int * __restrict sval) return (0); } -static int +static __inline int usem_wake(struct _usem *sem) { if (!sem->_has_waiters) @@ -339,7 +339,7 @@ usem_wake(struct _usem *sem) return _umtx_op(sem, UMTX_OP_SEM_WAKE, 0, NULL, NULL); } -static int +static __inline int usem_wait(struct _usem *sem, const struct timespec *timeout) { if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && @@ -387,7 +387,7 @@ sem_cancel_handler(void *arg) } while (0) -static int +static __inline int enable_async_cancel(void) { int old; @@ -396,7 +396,7 @@ enable_async_cancel(void) return (old); } -static void +static __inline void restore_async_cancel(int val) { _pthread_setcanceltype(val, NULL); @@ -413,7 +413,6 @@ _libc_sem_timedwait(sem_t * __restrict sem, return (-1); retval = 0; - _pthread_testcancel(); for (;;) { while ((val = sem->_kern._count) > 0) { if (atomic_cmpset_acq_int(&sem->_kern._count, val, val - 1)) @@ -464,7 +463,5 @@ _libc_sem_post(sem_t *sem) return (-1); atomic_add_rel_int(&sem->_kern._count, 1); - if (sem->_kern._has_waiters) - return usem_wake(&sem->_kern); - return (0); + return usem_wake(&sem->_kern); } |