Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Feb 2010 03:56:33 +0000 (UTC)
From:      David Xu <davidxu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r203414 - head/sys/kern
Message-ID:  <201002030356.o133uXks069344@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: davidxu
Date: Wed Feb  3 03:56:32 2010
New Revision: 203414
URL: http://svn.freebsd.org/changeset/base/203414

Log:
  After busied the lock, re-read state word before checking waiters flag,
  otherwise, the waiters bit may not be set and a wakeup is lost.
  
  Submitted by:	justin.teller at gmail dot com
  MFC after:	3 days

Modified:
  head/sys/kern/kern_umtx.c

Modified: head/sys/kern/kern_umtx.c
==============================================================================
--- head/sys/kern/kern_umtx.c	Wed Feb  3 03:26:00 2010	(r203413)
+++ head/sys/kern/kern_umtx.c	Wed Feb  3 03:56:32 2010	(r203414)
@@ -2526,6 +2526,12 @@ do_rw_rdlock(struct thread *td, struct u
 		umtxq_busy(&uq->uq_key);
 		umtxq_unlock(&uq->uq_key);
 
+		/*
+		 * re-read the state, in case it changed between the try-lock above
+		 * and the check below
+		 */
+		state = fuword32(__DEVOLATILE(int32_t *, &rwlock->rw_state));
+
 		/* set read contention bit */
 		while ((state & wrflags) && !(state & URWLOCK_READ_WAITERS)) {
 			oldstate = casuword32(&rwlock->rw_state, state, state | URWLOCK_READ_WAITERS);
@@ -2658,6 +2664,12 @@ do_rw_wrlock(struct thread *td, struct u
 		umtxq_busy(&uq->uq_key);
 		umtxq_unlock(&uq->uq_key);
 
+		/*
+		 * re-read the state, in case it changed between the try-lock above
+		 * and the check below
+		 */
+		state = fuword32(__DEVOLATILE(int32_t *, &rwlock->rw_state));
+
 		while (((state & URWLOCK_WRITE_OWNER) || URWLOCK_READER_COUNT(state) != 0) &&
 		       (state & URWLOCK_WRITE_WAITERS) == 0) {
 			oldstate = casuword32(&rwlock->rw_state, state, state | URWLOCK_WRITE_WAITERS);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002030356.o133uXks069344>