https://git.reactos.org/?p=reactos.git;a=commitdiff;h=90d795b0bf61e5bfe0e41…
commit 90d795b0bf61e5bfe0e4163e121d0700e1116ed0
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Feb 22 23:19:45 2020 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Feb 22 23:27:42 2020 +0100
[CONSRV] Keep a count of input events in the console queue + code simplifications.
- Update the documentation of members of CONSOLE_INPUT_BUFFER.
- Simplify ConDrvGetConsoleNumberOfInputEvents().
- Simplify ConDrvFlushConsoleInputBuffer().
- Use also GetConsoleInputBufferMode() more often.
---
win32ss/user/winsrv/consrv/condrv/coninput.c | 36 +++++++---------------
win32ss/user/winsrv/consrv/console.c | 2 +-
win32ss/user/winsrv/consrv/frontends/gui/conwnd.c | 2 +-
win32ss/user/winsrv/consrv/frontends/gui/guiterm.c | 4 +--
win32ss/user/winsrv/consrv/frontends/input.c | 2 +-
win32ss/user/winsrv/consrv/frontends/terminal.c | 2 ++
win32ss/user/winsrv/consrv/include/conio.h | 7 +++--
7 files changed, 22 insertions(+), 33 deletions(-)
diff --git a/win32ss/user/winsrv/consrv/condrv/coninput.c
b/win32ss/user/winsrv/consrv/condrv/coninput.c
index e3894d8a54c..a2041a0eae9 100644
--- a/win32ss/user/winsrv/consrv/condrv/coninput.c
+++ b/win32ss/user/winsrv/consrv/condrv/coninput.c
@@ -156,6 +156,7 @@ AddInputEvents(PCONSOLE Console,
/* Append the event to the beginning of the queue */
InsertHeadList(&Console->InputBuffer.InputEvents,
&ConInRec->ListEntry);
}
+ _InterlockedIncrement((PLONG)&Console->InputBuffer.NumberOfEvents);
// return STATUS_SUCCESS;
Status = STATUS_SUCCESS;
@@ -170,14 +171,16 @@ Done:
}
static VOID
-PurgeInputBuffer(PCONSOLE Console)
+PurgeInputBuffer(IN PCONSOLE_INPUT_BUFFER InputBuffer)
{
PLIST_ENTRY CurrentEntry;
ConsoleInput* Event;
- while (!IsListEmpty(&Console->InputBuffer.InputEvents))
+ /* Discard all entries in the input event queue */
+ _InterlockedExchange((PLONG)&InputBuffer->NumberOfEvents, 0);
+ while (!IsListEmpty(&InputBuffer->InputEvents))
{
- CurrentEntry = RemoveHeadList(&Console->InputBuffer.InputEvents);
+ CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
Event = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
ConsoleFreeHeap(Event);
}
@@ -206,6 +209,7 @@ ConDrvInitInputBuffer(IN PCONSOLE Console,
return Status;
Console->InputBuffer.InputBufferSize = InputBufferSize;
+ Console->InputBuffer.NumberOfEvents = 0;
InitializeListHead(&Console->InputBuffer.InputEvents);
Console->InputBuffer.Mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
@@ -216,7 +220,7 @@ ConDrvInitInputBuffer(IN PCONSOLE Console,
VOID NTAPI
ConDrvDeinitInputBuffer(IN PCONSOLE Console)
{
- PurgeInputBuffer(Console);
+ PurgeInputBuffer(&Console->InputBuffer);
CloseHandle(Console->InputBuffer.ActiveEvent);
}
@@ -303,6 +307,7 @@ ConDrvGetConsoleInput(IN PCONSOLE Console,
/* Remove the events from the queue if needed */
if (!KeepEvents)
{
+ _InterlockedDecrement((PLONG)&InputBuffer->NumberOfEvents);
RemoveEntryList(&Input->ListEntry);
ConsoleFreeHeap(Input);
}
@@ -352,9 +357,6 @@ NTSTATUS NTAPI
ConDrvFlushConsoleInputBuffer(IN PCONSOLE Console,
IN PCONSOLE_INPUT_BUFFER InputBuffer)
{
- PLIST_ENTRY CurrentEntry;
- ConsoleInput* Event;
-
if (Console == NULL || InputBuffer == NULL)
return STATUS_INVALID_PARAMETER;
@@ -362,12 +364,7 @@ ConDrvFlushConsoleInputBuffer(IN PCONSOLE Console,
ASSERT(Console == InputBuffer->Header.Console);
/* Discard all entries in the input event queue */
- while (!IsListEmpty(&InputBuffer->InputEvents))
- {
- CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
- Event = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
- ConsoleFreeHeap(Event);
- }
+ PurgeInputBuffer(InputBuffer);
ResetEvent(InputBuffer->ActiveEvent);
return STATUS_SUCCESS;
@@ -378,24 +375,13 @@ ConDrvGetConsoleNumberOfInputEvents(IN PCONSOLE Console,
IN PCONSOLE_INPUT_BUFFER InputBuffer,
OUT PULONG NumberOfEvents)
{
- PLIST_ENTRY CurrentInput;
-
if (Console == NULL || InputBuffer == NULL || NumberOfEvents == NULL)
return STATUS_INVALID_PARAMETER;
/* Validity check */
ASSERT(Console == InputBuffer->Header.Console);
- *NumberOfEvents = 0;
-
- /* If there are any events ... */
- CurrentInput = InputBuffer->InputEvents.Flink;
- while (CurrentInput != &InputBuffer->InputEvents)
- {
- CurrentInput = CurrentInput->Flink;
- (*NumberOfEvents)++;
- }
-
+ *NumberOfEvents = InputBuffer->NumberOfEvents;
return STATUS_SUCCESS;
}
diff --git a/win32ss/user/winsrv/consrv/console.c b/win32ss/user/winsrv/consrv/console.c
index b4e4668b5d5..ea39840cfdc 100644
--- a/win32ss/user/winsrv/consrv/console.c
+++ b/win32ss/user/winsrv/consrv/console.c
@@ -284,7 +284,7 @@ ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData,
CONSOLE_RUNNING,
LockConsole))
{
- InterlockedIncrement(&GrabConsole->ReferenceCount);
+ _InterlockedIncrement(&GrabConsole->ReferenceCount);
*Console = GrabConsole;
Status = STATUS_SUCCESS;
}
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
index ffc6939aa0c..f79ad141b2c 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
@@ -1711,7 +1711,7 @@ OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM
lParam)
break;
}
}
- else if (Console->InputBuffer.Mode & ENABLE_MOUSE_INPUT)
+ else if (GetConsoleInputBufferMode(Console) & ENABLE_MOUSE_INPUT)
{
INPUT_RECORD er;
WORD wKeyState = GET_KEYSTATE_WPARAM(wParam);
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
b/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
index 10142943520..d5a88a490e7 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
@@ -173,7 +173,7 @@ GuiConsoleInputThread(PVOID Param)
ASSERT(NewWindow == GuiData->hWindow);
- InterlockedIncrement(&WindowCount);
+ _InterlockedIncrement(&WindowCount);
//
// FIXME: TODO: Move everything there into conwnd.c!OnNcCreate()
@@ -238,7 +238,7 @@ GuiConsoleInputThread(PVOID Param)
NtSetEvent(GuiData->hGuiTermEvent, NULL);
- if (InterlockedDecrement(&WindowCount) == 0)
+ if (_InterlockedDecrement(&WindowCount) == 0)
{
DPRINT("CONSRV: Going to quit the Input Thread 0x%p\n",
InputThreadId);
goto Quit;
diff --git a/win32ss/user/winsrv/consrv/frontends/input.c
b/win32ss/user/winsrv/consrv/frontends/input.c
index 25a53a15c78..8bc0ad0ffae 100644
--- a/win32ss/user/winsrv/consrv/frontends/input.c
+++ b/win32ss/user/winsrv/consrv/frontends/input.c
@@ -125,7 +125,7 @@ ConioProcessKey(PCONSRV_CONSOLE Console, MSG* msg)
if (Fake) return;
/* Process Ctrl-C and Ctrl-Break */
- if ( Console->InputBuffer.Mode & ENABLE_PROCESSED_INPUT &&
+ if ( (GetConsoleInputBufferMode(Console) & ENABLE_PROCESSED_INPUT) &&
Down && (VirtualKeyCode == VK_PAUSE || VirtualKeyCode == 'C')
&&
(ShiftState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) ||
KeyState[VK_CONTROL] & 0x80) )
{
diff --git a/win32ss/user/winsrv/consrv/frontends/terminal.c
b/win32ss/user/winsrv/consrv/frontends/terminal.c
index 4d20af2a32e..ece6bb29933 100644
--- a/win32ss/user/winsrv/consrv/frontends/terminal.c
+++ b/win32ss/user/winsrv/consrv/frontends/terminal.c
@@ -361,6 +361,7 @@ ConSrvTermReadStream(IN OUT PTERMINAL This,
while (!Console->LineComplete &&
!IsListEmpty(&InputBuffer->InputEvents))
{
/* Remove an input event from the queue */
+ _InterlockedDecrement((PLONG)&InputBuffer->NumberOfEvents);
CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
if (IsListEmpty(&InputBuffer->InputEvents))
{
@@ -425,6 +426,7 @@ ConSrvTermReadStream(IN OUT PTERMINAL This,
while (i < NumCharsToRead &&
!IsListEmpty(&InputBuffer->InputEvents))
{
/* Remove an input event from the queue */
+ _InterlockedDecrement((PLONG)&InputBuffer->NumberOfEvents);
CurrentEntry = RemoveHeadList(&InputBuffer->InputEvents);
if (IsListEmpty(&InputBuffer->InputEvents))
{
diff --git a/win32ss/user/winsrv/consrv/include/conio.h
b/win32ss/user/winsrv/consrv/include/conio.h
index 87f22a77a67..17837c643f1 100644
--- a/win32ss/user/winsrv/consrv/include/conio.h
+++ b/win32ss/user/winsrv/consrv/include/conio.h
@@ -189,9 +189,10 @@ typedef struct _CONSOLE_INPUT_BUFFER
{
CONSOLE_IO_OBJECT Header; /* Object header - MUST BE IN FIRST PLACE */
- ULONG InputBufferSize; /* Size of this input buffer -- UNUSED!! */
- LIST_ENTRY InputEvents; /* List head for input event queue */
- HANDLE ActiveEvent; /* Event set when an input event is added in its
queue */
+ ULONG InputBufferSize; /* Size of this input buffer (maximum number of
events) -- UNUSED!! */
+ ULONG NumberOfEvents; /* Current number of events in the queue */
+ LIST_ENTRY InputEvents; /* Input events queue list head */
+ HANDLE ActiveEvent; /* Event set when an input event is added to the
queue */
USHORT Mode; /* Input buffer modes */
} CONSOLE_INPUT_BUFFER, *PCONSOLE_INPUT_BUFFER;