From 93f0162799a41c65d7ab67b3ad49865b95b3abac Mon Sep 17 00:00:00 2001 From: David Xu Date: Mon, 8 Feb 2010 07:31:05 +0000 Subject: [PATCH] Set waiters flag before checking semaphore's counter, otherwise we might lose a wakeup. Tested on postgresql database server. --- sys/kern/kern_umtx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 80559bafdefd..f80cb15e6b71 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -2853,6 +2853,8 @@ do_sem_wait(struct thread *td, struct _usem *sem, struct timespec *timeout) umtxq_insert(uq); umtxq_unlock(&uq->uq_key); + suword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters), 1); + count = fuword32(__DEVOLATILE(uint32_t *, &sem->_count)); if (count != 0) { umtxq_lock(&uq->uq_key); @@ -2863,11 +2865,6 @@ do_sem_wait(struct thread *td, struct _usem *sem, struct timespec *timeout) return (0); } - /* - * set waiters byte and sleep. - */ - suword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters), 1); - umtxq_lock(&uq->uq_key); umtxq_unbusy(&uq->uq_key); umtxq_unlock(&uq->uq_key);