ThreadingWin: Mutex::unlock() can be "over-unlocked".
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 20:35:18 +0000 (20:35 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 20:35:18 +0000 (20:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83725

Reviewed by David Levin.

In order to support the behavior of pthread_mutex_trylock(), the Windows Mutex class includes
a recursion counter which is incremented in Mutex::lock(), decremented in Mutex::unlock(),
and checked in Mutex::tryLock().  If the mutex is "over-unlocked", the counter wraps around to
MAX_INT, and subsequent calls to Mutex::trylock() will fail. Raise an ASSERT in this situation
so the "over-unlock" will be caught.

* wtf/ThreadingWin.cpp:
(WTF::Mutex::unlock): ASSERT if unlocking a non-locked mutex.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114028 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/ThreadingWin.cpp

index 2a14578..b90ea21 100644 (file)
@@ -1,3 +1,19 @@
+2012-04-12  Jer Noble  <jer.noble@apple.com>
+
+        ThreadingWin: Mutex::unlock() can be "over-unlocked".
+        https://bugs.webkit.org/show_bug.cgi?id=83725
+
+        Reviewed by David Levin.
+
+        In order to support the behavior of pthread_mutex_trylock(), the Windows Mutex class includes
+        a recursion counter which is incremented in Mutex::lock(), decremented in Mutex::unlock(),
+        and checked in Mutex::tryLock().  If the mutex is "over-unlocked", the counter wraps around to
+        MAX_INT, and subsequent calls to Mutex::trylock() will fail. Raise an ASSERT in this situation
+        so the "over-unlock" will be caught.
+
+        * wtf/ThreadingWin.cpp:
+        (WTF::Mutex::unlock): ASSERT if unlocking a non-locked mutex.
+
 2012-04-10  Mark Rowe  <mrowe@apple.com>
 
         <rdar://problem/10583749> WebKit2 should log to both ASL and stderr
index bc32262..4444827 100644 (file)
@@ -335,6 +335,7 @@ bool Mutex::tryLock()
 
 void Mutex::unlock()
 {
+    ASSERT(m_mutex.m_recursionCount);
     --m_mutex.m_recursionCount;
     LeaveCriticalSection(&m_mutex.m_internalMutex);
 }