From 71b636cfbd7cadf4ffa2c384ecd546c555a94d9a Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 17 May 1997 07:00:23 +0000 Subject: [PATCH] Change NT:MSGWAITFORMULTIPLEOBJECTS to check for messages that were removed from the input queue and placed on one of the screen queues. This eliminates a serious bug in Edwin: running an asynchronous evaluation that did no output would cause Edwin to lock up until the evaluation completed. --- v7/src/microcode/ntscreen.c | 15 ++++++++++++++- v7/src/microcode/ntscreen.h | 3 ++- v7/src/microcode/prntio.c | 23 +++++++++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/v7/src/microcode/ntscreen.c b/v7/src/microcode/ntscreen.c index 0e5a7ccfc..44915cb51 100644 --- a/v7/src/microcode/ntscreen.c +++ b/v7/src/microcode/ntscreen.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntscreen.c,v 1.28 1997/04/03 04:41:04 cph Exp $ +$Id: ntscreen.c,v 1.29 1997/05/17 07:00:14 cph Exp $ Copyright (c) 1993-97 Massachusetts Institute of Technology @@ -3266,6 +3266,19 @@ Screen_PeekEvent (HANDLE hwnd, SCREEN_EVENT * event) *event = screen->queue_head->event; return TRUE; } + +BOOL +Screen_pending_events_p (void) +{ + SCREEN screen = registered_screens; + while (screen) + { + if ((screen -> n_events) != 0) + return (TRUE); + screen = (screen -> registry_link); + } + return (FALSE); +} //--------------------------------------------------------------------------- diff --git a/v7/src/microcode/ntscreen.h b/v7/src/microcode/ntscreen.h index 7f6759895..84640622c 100644 --- a/v7/src/microcode/ntscreen.h +++ b/v7/src/microcode/ntscreen.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntscreen.h,v 1.14 1997/04/03 04:40:53 cph Exp $ +$Id: ntscreen.h,v 1.15 1997/05/17 06:59:56 cph Exp $ Copyright (c) 1993-97 Massachusetts Institute of Technology @@ -193,6 +193,7 @@ extern void screen_char_dimensions (HWND, int *, int *); // The following return false on no events extern BOOL Screen_GetEvent (HANDLE, SCREEN_EVENT *); extern BOOL Screen_PeekEvent (HANDLE, SCREEN_EVENT *); +extern BOOL Screen_pending_events_p (void); //--------------------------------------------------------------------------- // Messages diff --git a/v7/src/microcode/prntio.c b/v7/src/microcode/prntio.c index 3bdfa772d..759d34af1 100644 --- a/v7/src/microcode/prntio.c +++ b/v7/src/microcode/prntio.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: prntio.c,v 1.5 1997/04/03 04:41:15 cph Exp $ +$Id: prntio.c,v 1.6 1997/05/17 07:00:23 cph Exp $ Copyright (c) 1993-97 Massachusetts Institute of Technology @@ -125,17 +125,24 @@ wait_for_multiple_objects (DWORD nhand, HANDLE * handles, DWORD timeout, { DWORD result; MSG m; - /* This is a kludge. MsgWaitForMultipleObjects has a race - condition -- it ignores messages that are already queued. So - check the queue as late as possible before the call, in order - to minimize the window in which we can get stuck waiting for - a message that has already arrived. */ #ifdef TRACE_SCREEN_MSGS fprintf (trace_file, "MsgWaitForMultipleObjects: timeout=0x%x\n", timeout); fflush (trace_file); #endif - if (msgp && (PeekMessage ((&m), 0, 0, 0, PM_NOREMOVE))) - return (((m.message) == WM_SCHEME_INTERRUPT) ? (nhand + 2) : (nhand + 1)); + if (msgp) + { + if (Screen_pending_events_p ()) + return (nhand + 1); + /* This is a kludge. MsgWaitForMultipleObjects has a race + condition -- it ignores messages that are already queued. So + check the queue as late as possible before the call, in order + to minimize the window in which we can get stuck waiting for + a message that has already arrived. */ + if (PeekMessage ((&m), 0, 0, 0, PM_NOREMOVE)) + return (((m.message) == WM_SCHEME_INTERRUPT) + ? (nhand + 2) + : (nhand + 1)); + } result = (MsgWaitForMultipleObjects (nhand, handles, FALSE, timeout, QS_ALLINPUT)); #ifdef TRACE_SCREEN_MSGS -- 2.25.1