1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Only run one toplevel callback per event loop iteration.

This change attempts to reinstate as a universal property something
which was sporadically true of the ad-hockery that came before
toplevel callbacks: that if there's a _very long_ queue of things to
be done through the callback mechanism, the doing of them will be
interleaved with re-checks of other event sources, which might (e.g.)
cause a flag to be set which makes the next callback decide not to do
anything after all.

[originally from svn r10040]
This commit is contained in:
Simon Tatham
2013-09-15 14:05:31 +00:00
parent 043a762b5f
commit 5c4ce2fadf
8 changed files with 99 additions and 47 deletions

View File

@ -847,11 +847,20 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
while (1) {
HANDLE *handles;
int nhandles, n;
DWORD timeout;
if (toplevel_callback_pending()) {
timeout = 0;
} else {
timeout = INFINITE;
/* The messages seem unreliable; especially if we're being tricky */
term_set_focus(term, GetForegroundWindow() == hwnd);
}
handles = handle_get_events(&nhandles);
n = MsgWaitForMultipleObjects(nhandles, handles, FALSE, INFINITE,
QS_ALLINPUT);
n = MsgWaitForMultipleObjects(nhandles, handles, FALSE,
timeout, QS_ALLINPUT);
if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) {
handle_got_event(handles[n - WAIT_OBJECT_0]);
@ -859,20 +868,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
} else
sfree(handles);
run_toplevel_callbacks();
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
goto finished; /* two-level break */
if (!(IsWindow(logbox) && IsDialogMessage(logbox, &msg)))
DispatchMessage(&msg);
run_toplevel_callbacks();
}
/* The messages seem unreliable; especially if we're being tricky */
term_set_focus(term, GetForegroundWindow() == hwnd);
run_toplevel_callbacks();
}
finished: