Skip to content

Commit

Permalink
nvdaHelper remote: injection: inprocMgrThreadFunc():
Browse files Browse the repository at this point in the history
	* Even though we only register for in-context events, conhost always delivers console events out-of-context even when we're in the same process. Therefore, introduce a message loop to avoid lagging these events.
	* When registering for win events, use EVENT_MIN and EVENT_MAX. Previously, we were using 0xFFFFFFFF for max. It seems that Windows delivers some events above 0x80000000, which is actually above EVENT_MAX, but these don't seem to be documented anywhere. We certainly don't need them in any case.
Fixes performance degradation in Windows consoles (again).

Fixes #622.
  • Loading branch information
jcsteh committed Aug 25, 2010
1 parent afc89d7 commit 88ebf13
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions source/NVDAHelper/remote/injection.cpp
Expand Up @@ -106,7 +106,7 @@ DWORD WINAPI inprocMgrThreadFunc(LPVOID data) {
//As long as we have successfully retreaved handles for NVDA's process and the event, then go on and initialize, wait and terminate.
if(waitHandles[0]&&waitHandles[1]) {
//Register for all winEvents in this process.
inprocWinEventHookID=SetWinEventHook(0,0XFFFFFFFF,dllHandle,inproc_winEventCallback,GetCurrentProcessId(),0,WINEVENT_INCONTEXT);
inprocWinEventHookID=SetWinEventHook(EVENT_MIN,EVENT_MAX,dllHandle,inproc_winEventCallback,GetCurrentProcessId(),0,WINEVENT_INCONTEXT);
if(inprocWinEventHookID==0) {
LOG_ERROR(L"SetWinEventHook failed");
}
Expand All @@ -122,7 +122,17 @@ DWORD WINAPI inprocMgrThreadFunc(LPVOID data) {
#ifndef NDEBUG
Beep(660,75);
#endif
WaitForMultipleObjects(2,waitHandles,FALSE,INFINITE);
// Even though we only registered for in-context winEvents, we may still receive some out-of-context events; e.g. console events.
// Therefore, we must have a message loop.
// Otherwise, any out-of-context events will cause major lag which increases over time.
do {
// Consume and handle all pending messages.
MSG msg;
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} while(MsgWaitForMultipleObjects(2,waitHandles,FALSE,INFINITE,QS_ALLINPUT)==WAIT_OBJECT_0+2);
assert(inprocMgrThreadHandle);
inprocThreadsLock.acquire();
CloseHandle(inprocMgrThreadHandle);
Expand Down

0 comments on commit 88ebf13

Please sign in to comment.