Author: hbelusca Date: Sat Dec 7 00:01:24 2013 New Revision: 61239
URL: http://svn.reactos.org/svn/reactos?rev=61239&view=rev Log: [NTVDM] - Last race condition fix (see revision 61230). - Add a comment why we do twice the same emptiness check (one before holding the mutex and one just after).
Modified: branches/ntvdm/subsystems/ntvdm/ps2.c
Modified: branches/ntvdm/subsystems/ntvdm/ps2.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ps2.c?rev... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/ps2.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/ps2.c [iso-8859-1] Sat Dec 7 00:01:24 2013 @@ -31,10 +31,16 @@
static BOOLEAN KeyboardQueuePush(BYTE ScanCode) { + BOOLEAN Result = TRUE; + + WaitForSingleObject(QueueMutex, INFINITE); + /* Check if the keyboard queue is full */ - WaitForSingleObject(QueueMutex, INFINITE); - - if (!KeyboardQueueEmpty && (KeyboardQueueStart == KeyboardQueueEnd)) return FALSE; + if (!KeyboardQueueEmpty && (KeyboardQueueStart == KeyboardQueueEnd)) + { + Result = FALSE; + goto Done; + }
/* Insert the value in the queue */ KeyboardQueue[KeyboardQueueEnd] = ScanCode; @@ -44,19 +50,24 @@ /* Since we inserted a value, it's not empty anymore */ KeyboardQueueEmpty = FALSE;
+Done: ReleaseMutex(QueueMutex); - return TRUE; + return Result; }
static BOOLEAN KeyboardQueuePop(BYTE *ScanCode) { BOOLEAN Result = TRUE;
- /* Make sure the keyboard queue is not empty */ + /* Make sure the keyboard queue is not empty (fast check) */ if (KeyboardQueueEmpty) return FALSE;
WaitForSingleObject(QueueMutex, INFINITE);
+ /* + * Recheck whether keyboard queue is not empty (it may + * have been changed after having grabbed the mutex). + */ if (KeyboardQueueEmpty) { Result = FALSE;