From 7fc02cf80b3b22f9765e15415e1aa0a175a3aca8 Mon Sep 17 00:00:00 2001 From: davygrvy Date: Wed, 3 Mar 2004 10:44:41 +0000 Subject: * win/tclWinNotify.c (Tcl_WaitForEvent) : Allows an idling notifier to service "Asynchronous Procedure Calls" from its wait state. Only useful for extension authors who decide they might want to try "completion routines" with WriteFileEx(), as an example. From experience, I recommend that "completion ports" should be used instead as the execution of the callbacks are more managable. --- win/tclWinNotify.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/win/tclWinNotify.c b/win/tclWinNotify.c index 65faf8e..02e8d64 100644 --- a/win/tclWinNotify.c +++ b/win/tclWinNotify.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinNotify.c,v 1.13 2003/12/24 04:18:22 davygrvy Exp $ + * RCS: @(#) $Id: tclWinNotify.c,v 1.14 2004/03/03 10:44:41 davygrvy Exp $ */ #include "tclWinInt.h" @@ -458,18 +458,27 @@ Tcl_WaitForEvent( if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { /* * Wait for something to happen (a signal from another thread, a - * message, or timeout). + * message, or timeout) or loop servicing asynchronous procedure + * calls queued to this thread. */ - result = MsgWaitForMultipleObjects(1, &tsdPtr->event, FALSE, timeout, - QS_ALLINPUT); +again: + result = MsgWaitForMultipleObjectsEx(1, &tsdPtr->event, timeout, + QS_ALLINPUT, MWMO_ALERTABLE); + if (result == WAIT_IO_COMPLETION) { + goto again; + } else if (result == WAIT_FAILED) { + status = -1; + goto end; + } } /* * Check to see if there are any messages to process. */ - if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { + if (result == (WAIT_OBJECT_0 + 1) || + PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { /* * Retrieve and dispatch the first message. */ @@ -499,6 +508,7 @@ Tcl_WaitForEvent( status = 0; } +end: ResetEvent(tsdPtr->event); return status; } -- cgit v0.12