Author: fireball Date: Thu Aug 21 16:07:52 2008 New Revision: 35516
URL: http://svn.reactos.org/svn/reactos?rev=35516&view=rev Log: - "When releasing the gmutex my awesome code was removing the woken flag" (c) Alex Ionescu.
Modified: trunk/reactos/ntoskrnl/ke/gmutex.c
Modified: trunk/reactos/ntoskrnl/ke/gmutex.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/gmutex.c?rev=35... ============================================================================== --- trunk/reactos/ntoskrnl/ke/gmutex.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ke/gmutex.c [iso-8859-1] Thu Aug 21 16:07:52 2008 @@ -79,6 +79,9 @@ /* Ok, the wait is done, so set the new bits */ BitsToRemove = GM_LOCK_BIT | GM_LOCK_WAITER_WOKEN; BitsToAdd = GM_LOCK_WAITER_WOKEN; + + /* We depend on these bits being just right */ + ASSERT((GM_LOCK_WAITER_WOKEN * 2) == GM_LOCK_WAITER_INC); } }
@@ -103,7 +106,7 @@ FASTCALL KiReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex) { - LONG OldValue; + LONG OldValue, NewValue;
/* Destroy the Owner */ GuardedMutex->Owner = NULL; @@ -117,10 +120,14 @@ { /* Update the Oldvalue to what it should be now */ OldValue |= GM_LOCK_BIT; + + /* The mutex will be woken, minus one waiter */ + NewValue = (OldValue | GM_LOCK_WAITER_WOKEN); + NewValue &= ~GM_LOCK_WAITER_INC;
/* Remove the Woken bit */ if (InterlockedCompareExchange(&GuardedMutex->Count, - OldValue - GM_LOCK_WAITER_WOKEN, + NewValue, OldValue) == OldValue) { /* Signal the Gate */