svn commit: r215652 - head/sys/kern

David Xu davidxu at FreeBSD.org
Mon Nov 22 02:42:03 UTC 2010


Author: davidxu
Date: Mon Nov 22 02:42:02 2010
New Revision: 215652
URL: http://svn.freebsd.org/changeset/base/215652

Log:
  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

Modified:
  head/sys/kern/kern_umtx.c

Modified: head/sys/kern/kern_umtx.c
==============================================================================
--- head/sys/kern/kern_umtx.c	Mon Nov 22 01:28:29 2010	(r215651)
+++ head/sys/kern/kern_umtx.c	Mon Nov 22 02:42:02 2010	(r215652)
@@ -2839,7 +2839,8 @@ do_sem_wait(struct thread *td, struct _u
 	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) {


More information about the svn-src-all mailing list