Use atomic instruction to set _has_writer, otherwise there is a race

causes userland to not wake up a thread sleeping in kernel.

MFC after: 3 days
This commit is contained in:
David Xu 2010-11-22 02:42:02 +00:00
parent e64ac239f6
commit b169d0efa1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215652

View file

@ -2839,7 +2839,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);
if (fuword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters)) == 0)
casuword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters), 0, 1);
count = fuword32(__DEVOLATILE(uint32_t *, &sem->_count));
if (count != 0) {