Author: aandrejevic
Date: Fri Dec 6 04:51:47 2013
New Revision: 61230
URL:
http://svn.reactos.org/svn/reactos?rev=61230&view=rev
Log:
[NTVDM]
Fix race conditions.
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?re…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ps2.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ps2.c [iso-8859-1] Fri Dec 6 04:51:47 2013
@@ -32,9 +32,9 @@
static BOOLEAN KeyboardQueuePush(BYTE ScanCode)
{
/* Check if the keyboard queue is full */
+ WaitForSingleObject(QueueMutex, INFINITE);
+
if (!KeyboardQueueEmpty && (KeyboardQueueStart == KeyboardQueueEnd)) return
FALSE;
-
- WaitForSingleObject(QueueMutex, INFINITE);
/* Insert the value in the queue */
KeyboardQueue[KeyboardQueueEnd] = ScanCode;
@@ -50,10 +50,18 @@
static BOOLEAN KeyboardQueuePop(BYTE *ScanCode)
{
+ BOOLEAN Result = TRUE;
+
/* Make sure the keyboard queue is not empty */
if (KeyboardQueueEmpty) return FALSE;
WaitForSingleObject(QueueMutex, INFINITE);
+
+ if (KeyboardQueueEmpty)
+ {
+ Result = FALSE;
+ goto Done;
+ }
/* Get the scan code */
*ScanCode = KeyboardQueue[KeyboardQueueStart];
@@ -68,8 +76,9 @@
KeyboardQueueEmpty = TRUE;
}
+Done:
ReleaseMutex(QueueMutex);
- return TRUE;
+ return Result;
}
/* PUBLIC FUNCTIONS ***********************************************************/