summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixNotfy.c
diff options
context:
space:
mode:
authordas <das>2009-04-10 18:02:36 (GMT)
committerdas <das>2009-04-10 18:02:36 (GMT)
commit2858f83307b48cadf03d1ae69cb92820edf3e1cc (patch)
tree73c1d2c98db1bdf47db23cff6bb36aad46156ef8 /unix/tclUnixNotfy.c
parent9bdf20b285315e722860d65d2ada928f6ece07f0 (diff)
downloadtcl-2858f83307b48cadf03d1ae69cb92820edf3e1cc.zip
tcl-2858f83307b48cadf03d1ae69cb92820edf3e1cc.tar.gz
tcl-2858f83307b48cadf03d1ae69cb92820edf3e1cc.tar.bz2
* macosx/tclMacOSXNotify.c: revise CoreFoundation notifier to allow
* unix/tclUnixChan.c: embedding into applications that * unix/tclUnixEvent.c: already have a CFRunLoop running and want to run the tcl event loop via Tcl_ServiceModeHook(TCL_SERVICE_ALL). * macosx/tclMacOSXNotify.c: add CFRunLoop based Tcl_Sleep() and * unix/tclUnixChan.c: TclUnixWaitForFile() implementations * unix/tclUnixEvent.c: and disable select() based ones in CoreFoundation builds. * unix/tclUnixNotify.c: simplify, sync with tclMacOSXNotify.c. * generic/tclInt.decls: add TclMacOSXNotifierAddRunLoopMode() * generic/tclIntPlatDecls.h: internal API, regen. * generic/tclStubInit.c:
Diffstat (limited to 'unix/tclUnixNotfy.c')
-rw-r--r--unix/tclUnixNotfy.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c
index 434ae84..edcd884 100644
--- a/unix/tclUnixNotfy.c
+++ b/unix/tclUnixNotfy.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: tclUnixNotfy.c,v 1.38 2008/12/12 16:07:18 ferrieux Exp $
+ * RCS: @(#) $Id: tclUnixNotfy.c,v 1.39 2009/04/10 18:02:37 das Exp $
*/
#include "tclInt.h"
@@ -135,7 +135,7 @@ static ThreadSpecificData *waitingListPtr = NULL;
* pipe. Hence writing to this file descriptor will cause the select() system
* call to return and wake up the notifier thread.
*
- * You must hold the notifierMutex lock before accessing this list.
+ * You must hold the notifierMutex lock before writing to the pipe.
*/
static int triggerPipe = -1;
@@ -552,15 +552,17 @@ Tcl_DeleteFileHandler(
*/
if (fd+1 == tsdPtr->numFdBits) {
- tsdPtr->numFdBits = 0;
+ int numFdBits = 0;
+
for (i = fd-1; i >= 0; i--) {
if (FD_ISSET(i, &(tsdPtr->checkMasks.readable))
|| FD_ISSET(i, &(tsdPtr->checkMasks.writable))
|| FD_ISSET(i, &(tsdPtr->checkMasks.exceptional))) {
- tsdPtr->numFdBits = i+1;
+ numFdBits = i+1;
break;
}
}
+ tsdPtr->numFdBits = numFdBits;
}
/*
@@ -677,10 +679,9 @@ Tcl_WaitForEvent(
FileHandler *filePtr;
FileHandlerEvent *fileEvPtr;
int mask;
- Tcl_Time myTime;
+ Tcl_Time vTime;
#ifdef TCL_THREADS
int waitForFiles;
- Tcl_Time *myTimePtr;
#else
/*
* Impl. notes: timeout & timeoutPtr are used if, and only if threads
@@ -706,22 +707,15 @@ Tcl_WaitForEvent(
* the handler to do this scaling.
*/
- myTime.sec = timePtr->sec;
- myTime.usec = timePtr->usec;
-
- if (myTime.sec != 0 || myTime.usec != 0) {
- tclScaleTimeProcPtr(&myTime, tclTimeClientData);
+ if (timePtr->sec != 0 || timePtr->usec != 0) {
+ vTime = *timePtr;
+ tclScaleTimeProcPtr(&vTime, tclTimeClientData);
+ timePtr = &vTime;
}
-
-#ifdef TCL_THREADS
- myTimePtr = &myTime;
-#else
- timeout.tv_sec = myTime.sec;
- timeout.tv_usec = myTime.usec;
- timeoutPtr = &timeout;
-#endif /* TCL_THREADS */
-
#ifndef TCL_THREADS
+ timeout.tv_sec = timePtr->sec;
+ timeout.tv_usec = timePtr->usec;
+ timeoutPtr = &timeout;
} else if (tsdPtr->numFdBits == 0) {
/*
* If there are no threads, no timeout, and no fds registered, then
@@ -732,11 +726,7 @@ Tcl_WaitForEvent(
*/
return -1;
-#endif /* !TCL_THREADS */
} else {
-#ifdef TCL_THREADS
- myTimePtr = NULL;
-#else
timeoutPtr = NULL;
#endif /* TCL_THREADS */
}
@@ -749,8 +739,7 @@ Tcl_WaitForEvent(
Tcl_MutexLock(&notifierMutex);
- waitForFiles = (tsdPtr->numFdBits > 0);
- if (myTimePtr != NULL && myTimePtr->sec == 0 && (myTimePtr->usec == 0
+ if (timePtr != NULL && timePtr->sec == 0 && (timePtr->usec == 0
#if defined(__APPLE__) && defined(__LP64__)
/*
* On 64-bit Darwin, pthread_cond_timedwait() appears to have a
@@ -759,7 +748,7 @@ Tcl_WaitForEvent(
* a workaround, when given a very brief timeout, just do a
* poll. [Bug 1457797]
*/
- || myTimePtr->usec < 10
+ || timePtr->usec < 10
#endif
)) {
/*
@@ -772,8 +761,9 @@ Tcl_WaitForEvent(
waitForFiles = 1;
tsdPtr->pollState = POLL_WANT;
- myTimePtr = NULL;
+ timePtr = NULL;
} else {
+ waitForFiles = (tsdPtr->numFdBits > 0);
tsdPtr->pollState = 0;
}
@@ -800,7 +790,7 @@ Tcl_WaitForEvent(
FD_ZERO(&(tsdPtr->readyMasks.exceptional));
if (!tsdPtr->eventReady) {
- Tcl_ConditionWait(&tsdPtr->waitCV, &notifierMutex, myTimePtr);
+ Tcl_ConditionWait(&tsdPtr->waitCV, &notifierMutex, timePtr);
}
tsdPtr->eventReady = 0;