diff options
Diffstat (limited to 'generic/tclNotify.c')
-rw-r--r-- | generic/tclNotify.c | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/generic/tclNotify.c b/generic/tclNotify.c index e76bca8..b45539a 100644 --- a/generic/tclNotify.c +++ b/generic/tclNotify.c @@ -17,14 +17,7 @@ #include "tclInt.h" -/* - * Module-scope struct of notifier hooks that are checked in the default - * notifier functions (for overriding via Tcl_SetNotifier). - */ - -Tcl_NotifierProcs tclNotifierHooks = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL -}; +extern TclStubs tclStubs; /* * For each event source (created with Tcl_CreateEventSource) there is a @@ -95,7 +88,7 @@ TCL_DECLARE_MUTEX(listLock) */ static void QueueEvent(ThreadSpecificData *tsdPtr, - Tcl_Event *evPtr, Tcl_QueuePosition position); + Tcl_Event* evPtr, Tcl_QueuePosition position); /* *---------------------------------------------------------------------- @@ -133,7 +126,7 @@ TclInitNotifier(void) tsdPtr = TCL_TSD_INIT(&dataKey); tsdPtr->threadId = threadId; - tsdPtr->clientData = Tcl_InitNotifier(); + tsdPtr->clientData = tclStubs.tcl_InitNotifier(); tsdPtr->initialized = 1; tsdPtr->nextPtr = firstNotifierPtr; firstNotifierPtr = tsdPtr; @@ -181,7 +174,7 @@ TclFinalizeNotifier(void) for (evPtr = tsdPtr->firstEventPtr; evPtr != NULL; ) { hold = evPtr; evPtr = evPtr->nextPtr; - ckfree(hold); + ckfree((char *) hold); } tsdPtr->firstEventPtr = NULL; tsdPtr->lastEventPtr = NULL; @@ -189,7 +182,9 @@ TclFinalizeNotifier(void) Tcl_MutexLock(&listLock); - Tcl_FinalizeNotifier(tsdPtr->clientData); + if (tclStubs.tcl_FinalizeNotifier) { + tclStubs.tcl_FinalizeNotifier(tsdPtr->clientData); + } Tcl_MutexFinalize(&(tsdPtr->queueMutex)); for (prevPtrPtr = &firstNotifierPtr; *prevPtrPtr != NULL; prevPtrPtr = &((*prevPtrPtr)->nextPtr)) { @@ -216,8 +211,9 @@ TclFinalizeNotifier(void) * None. * * Side effects: - * Set the tclNotifierHooks global, which is checked in the default - * notifier functions. + * Overstomps part of the stub vector. This relies on hooks added to the + * default functions in case those are called directly (i.e., not through + * the stub table.) * *---------------------------------------------------------------------- */ @@ -226,7 +222,16 @@ void Tcl_SetNotifier( Tcl_NotifierProcs *notifierProcPtr) { - tclNotifierHooks = *notifierProcPtr; +#if !defined(__WIN32__) /* UNIX */ + tclStubs.tcl_CreateFileHandler = notifierProcPtr->createFileHandlerProc; + tclStubs.tcl_DeleteFileHandler = notifierProcPtr->deleteFileHandlerProc; +#endif + tclStubs.tcl_SetTimer = notifierProcPtr->setTimerProc; + tclStubs.tcl_WaitForEvent = notifierProcPtr->waitForEventProc; + tclStubs.tcl_InitNotifier = notifierProcPtr->initNotifierProc; + tclStubs.tcl_FinalizeNotifier = notifierProcPtr->finalizeNotifierProc; + tclStubs.tcl_AlertNotifier = notifierProcPtr->alertNotifierProc; + tclStubs.tcl_ServiceModeHook = notifierProcPtr->serviceModeHookProc; } /* @@ -276,7 +281,7 @@ Tcl_CreateEventSource( * checkProc. */ { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - EventSource *sourcePtr = ckalloc(sizeof(EventSource)); + EventSource *sourcePtr = (EventSource *) ckalloc(sizeof(EventSource)); sourcePtr->setupProc = setupProc; sourcePtr->checkProc = checkProc; @@ -297,7 +302,7 @@ Tcl_CreateEventSource( * None. * * Side effects: - * The given event source is canceled, so its function will never again + * The given event source is cancelled, so its function will never again * be called. If no such source exists, nothing happens. * *---------------------------------------------------------------------- @@ -330,7 +335,7 @@ Tcl_DeleteEventSource( } else { prevPtr->nextPtr = sourcePtr->nextPtr; } - ckfree(sourcePtr); + ckfree((char *) sourcePtr); return; } } @@ -353,7 +358,7 @@ Tcl_DeleteEventSource( void Tcl_QueueEvent( - Tcl_Event *evPtr, /* Event to add to queue. The storage space + Tcl_Event* evPtr, /* Event to add to queue. The storage space * must have been allocated the caller with * malloc (ckalloc), and it becomes the * property of the event queue. It will be @@ -362,7 +367,6 @@ Tcl_QueueEvent( * TCL_QUEUE_MARK. */ { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - QueueEvent(tsdPtr, evPtr, position); } @@ -412,7 +416,7 @@ Tcl_ThreadQueueEvent( if (tsdPtr) { QueueEvent(tsdPtr, evPtr, position); } else { - ckfree(evPtr); + ckfree((char *) evPtr); } Tcl_MutexUnlock(&listLock); } @@ -516,13 +520,14 @@ QueueEvent( void Tcl_DeleteEvents( Tcl_EventDeleteProc *proc, /* The function to call. */ - ClientData clientData) /* The type-specific data. */ + ClientData clientData) /* The type-specific data. */ { Tcl_Event *evPtr; /* Pointer to the event being examined */ Tcl_Event *prevPtr; /* Pointer to evPtr's predecessor, or NULL if * evPtr designates the first event in the * queue for the thread. */ - Tcl_Event *hold; + Tcl_Event* hold; + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); Tcl_MutexLock(&(tsdPtr->queueMutex)); @@ -535,7 +540,7 @@ Tcl_DeleteEvents( prevPtr = NULL; evPtr = tsdPtr->firstEventPtr; while (evPtr != NULL) { - if (proc(evPtr, clientData) == 1) { + if ((*proc)(evPtr, clientData) == 1) { /* * This event should be deleted. Unlink it. */ @@ -563,7 +568,7 @@ Tcl_DeleteEvents( hold = evPtr; evPtr = evPtr->nextPtr; - ckfree(hold); + ckfree((char *) hold); } else { /* * Event is to be retained. @@ -667,7 +672,7 @@ Tcl_ServiceEvent( */ Tcl_MutexUnlock(&(tsdPtr->queueMutex)); - result = proc(evPtr, flags); + result = (*proc)(evPtr, flags); Tcl_MutexLock(&(tsdPtr->queueMutex)); if (result) { @@ -702,7 +707,7 @@ Tcl_ServiceEvent( } } if (evPtr) { - ckfree(evPtr); + ckfree((char *) evPtr); } Tcl_MutexUnlock(&(tsdPtr->queueMutex)); return 1; @@ -769,7 +774,9 @@ Tcl_SetServiceMode( oldMode = tsdPtr->serviceMode; tsdPtr->serviceMode = mode; - Tcl_ServiceModeHook(mode); + if (tclStubs.tcl_ServiceModeHook) { + tclStubs.tcl_ServiceModeHook(mode); + } return oldMode; } @@ -794,7 +801,7 @@ Tcl_SetServiceMode( void Tcl_SetMaxBlockTime( - const Tcl_Time *timePtr) /* Specifies a maximum elapsed time for the + Tcl_Time *timePtr) /* Specifies a maximum elapsed time for the * next blocking operation in the event * tsdPtr-> */ { @@ -927,7 +934,7 @@ Tcl_DoOneEvent( for (sourcePtr = tsdPtr->firstEventSourcePtr; sourcePtr != NULL; sourcePtr = sourcePtr->nextPtr) { if (sourcePtr->setupProc) { - sourcePtr->setupProc(sourcePtr->clientData, flags); + (sourcePtr->setupProc)(sourcePtr->clientData, flags); } } tsdPtr->inTraversal = 0; @@ -956,7 +963,7 @@ Tcl_DoOneEvent( for (sourcePtr = tsdPtr->firstEventSourcePtr; sourcePtr != NULL; sourcePtr = sourcePtr->nextPtr) { if (sourcePtr->checkProc) { - sourcePtr->checkProc(sourcePtr->clientData, flags); + (sourcePtr->checkProc)(sourcePtr->clientData, flags); } } @@ -1066,13 +1073,13 @@ Tcl_ServiceAll(void) for (sourcePtr = tsdPtr->firstEventSourcePtr; sourcePtr != NULL; sourcePtr = sourcePtr->nextPtr) { if (sourcePtr->setupProc) { - sourcePtr->setupProc(sourcePtr->clientData, TCL_ALL_EVENTS); + (sourcePtr->setupProc)(sourcePtr->clientData, TCL_ALL_EVENTS); } } for (sourcePtr = tsdPtr->firstEventSourcePtr; sourcePtr != NULL; sourcePtr = sourcePtr->nextPtr) { if (sourcePtr->checkProc) { - sourcePtr->checkProc(sourcePtr->clientData, TCL_ALL_EVENTS); + (sourcePtr->checkProc)(sourcePtr->clientData, TCL_ALL_EVENTS); } } @@ -1125,7 +1132,9 @@ Tcl_ThreadAlert( Tcl_MutexLock(&listLock); for (tsdPtr = firstNotifierPtr; tsdPtr; tsdPtr = tsdPtr->nextPtr) { if (tsdPtr->threadId == threadId) { - Tcl_AlertNotifier(tsdPtr->clientData); + if (tclStubs.tcl_AlertNotifier) { + tclStubs.tcl_AlertNotifier(tsdPtr->clientData); + } break; } } |