Set the owner to 0 while releasing a recursive mutex
authorGeoffroy Couprie <geo.couprie@gmail.com>
Wed, 10 Sep 2008 12:26:43 +0000 (14:26 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Wed, 10 Sep 2008 15:16:42 +0000 (18:16 +0300)
I (and dionoea too, I think) encountered an "assertion failed self ==
0" when trying to play a file on win32. I think the following patch
solves this issue. If I understand correcly, the intended behaviour
was to zero the owner field of the mutex when releasing it.

Modified by Courmisch to use InterlockedExchange() directly.

Signed-off-by: Rémi Denis-Courmont <rdenis@simphalempin.com>
src/misc/threads.c

index e12bef2..e4eeaf8 100644 (file)
@@ -352,7 +352,7 @@ void vlc_mutex_lock (vlc_mutex_t *p_mutex)
 
         /* We need to lock this recursive mutex */
         EnterCriticalSection (&p_mutex->mutex);
-        self = InterlockedCompareExchange (&p_mutex->owner, self, 0);
+        self = InterlockedExchange (&p_mutex->owner, self);
         assert (self == 0); /* no previous owner */
         return;
     }
@@ -383,9 +383,8 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
         }
 
         /* We release the mutex */
-        DWORD self = GetCurrentThreadId ();
-        self = InterlockedCompareExchange (&p_mutex->owner, self, 0);
-        assert (self == GetCurrentThreadId ());
+        DWORD self = InterlockedExchange (&p_mutex->owner, 0);
+        assert (self == 0);
         /* fall through */
     }
     LeaveCriticalSection (&p_mutex->mutex);