diff options
-rw-r--r-- | generic/tclIO.c | 13 | ||||
-rw-r--r-- | generic/tclInt.h | 3 | ||||
-rw-r--r-- | generic/tclThread.c | 39 | ||||
-rw-r--r-- | unix/tclUnixNotfy.c | 363 | ||||
-rw-r--r-- | unix/tclUnixThrd.c | 60 | ||||
-rw-r--r-- | win/tclWinThrd.c | 54 |
6 files changed, 244 insertions, 288 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index 8b01be2..fe28821 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -5754,6 +5754,7 @@ DoReadChars( assert( statePtr->inputEncodingFlags & TCL_ENCODING_END ); assert( !GotFlag(statePtr, CHANNEL_BLOCKED|INPUT_SAW_CR) ); + /* TODO: We don't need this call? */ UpdateInterest(chanPtr); return 0; } @@ -5765,6 +5766,7 @@ DoReadChars( } ResetFlag(statePtr, CHANNEL_BLOCKED|CHANNEL_EOF); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; + /* TODO: We don't need this call? */ UpdateInterest(chanPtr); return 0; } @@ -8285,6 +8287,11 @@ Tcl_NotifyChannel( */ if (chanPtr->typePtr != NULL) { + /* + * TODO: This call may not be needed. If a handler induced a + * change in interest, that handler should have made its own + * UpdateInterest() call, one would think. + */ UpdateInterest(chanPtr); } @@ -9663,6 +9670,7 @@ DoRead( assert( statePtr->inputEncodingFlags & TCL_ENCODING_END ); assert( !GotFlag(statePtr, CHANNEL_BLOCKED|INPUT_SAW_CR) ); + /* TODO: Don't need this call */ UpdateInterest(chanPtr); return 0; } @@ -9674,6 +9682,7 @@ DoRead( } ResetFlag(statePtr, CHANNEL_BLOCKED|CHANNEL_EOF); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; + /* TODO: Don't need this call */ UpdateInterest(chanPtr); return 0; } @@ -9740,7 +9749,6 @@ DoRead( */ if (bytesToRead == 0) { - UpdateInterest(chanPtr); break; } @@ -9749,7 +9757,6 @@ DoRead( */ if (GotFlag(statePtr, CHANNEL_STICKY_EOF)) { - UpdateInterest(chanPtr); break; } @@ -9774,7 +9781,6 @@ DoRead( } else if (statePtr->flags & CHANNEL_BLOCKED) { /* ...and we cannot get more now. */ SetFlag(statePtr, CHANNEL_NEED_MORE_DATA); - UpdateInterest(chanPtr); break; } else { /* ... so we need to get some. */ @@ -9826,6 +9832,7 @@ DoRead( || Tcl_InputBuffered((Tcl_Channel)chanPtr) == 0); assert( !(GotFlag(statePtr, CHANNEL_EOF|CHANNEL_BLOCKED) == (CHANNEL_EOF|CHANNEL_BLOCKED)) ); + UpdateInterest(chanPtr); TclChannelRelease((Tcl_Channel)chanPtr); return (int)(p - dst); } diff --git a/generic/tclInt.h b/generic/tclInt.h index fbc4d3f..8716b75 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3011,9 +3011,6 @@ MODULE_SCOPE void TclpInitUnlock(void); MODULE_SCOPE Tcl_Obj * TclpObjListVolumes(void); MODULE_SCOPE void TclpMasterLock(void); MODULE_SCOPE void TclpMasterUnlock(void); -MODULE_SCOPE void TclpMutexLock(void); -MODULE_SCOPE void TclpMutexUnlock(void); -MODULE_SCOPE void TclMutexUnlockAndFinalize(Tcl_Mutex *mutex); MODULE_SCOPE int TclpMatchFiles(Tcl_Interp *interp, char *separators, Tcl_DString *dirPtr, char *pattern, char *tail); MODULE_SCOPE int TclpObjNormalizePath(Tcl_Interp *interp, diff --git a/generic/tclThread.c b/generic/tclThread.c index 7882a48..198fa6a 100644 --- a/generic/tclThread.c +++ b/generic/tclThread.c @@ -284,45 +284,6 @@ Tcl_MutexFinalize( /* *---------------------------------------------------------------------- * - * TclMutexUnlockAndFinalize -- - * - * This procedure is invoked to unlock and then finalize a mutex. - * The mutex must have been locked by Tcl_MutexLock. It is also - * removed from the list of remembered objects. The mutex can no - * longer be used after calling this procedure. - * - * Results: - * None. - * - * Side effects: - * Remove the mutex from the list. - * - *---------------------------------------------------------------------- - */ - -void -TclMutexUnlockAndFinalize( - Tcl_Mutex *mutexPtr) -{ -#ifdef TCL_THREADS - Tcl_Mutex mutex; -#endif - TclpMasterLock(); - TclpMutexLock(); -#ifdef TCL_THREADS - mutex = *mutexPtr; - *mutexPtr = NULL; /* Force it to be created again. */ - Tcl_MutexUnlock(&mutex); - TclpFinalizeMutex(&mutex); -#endif - ForgetSyncObject(mutexPtr, &mutexRecord); - TclpMutexUnlock(); - TclpMasterUnlock(); -} - -/* - *---------------------------------------------------------------------- - * * TclRememberCondition * * Keep a list of condition variables used during finalization. diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index 9bcd51a..78f0741 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.c @@ -1,3 +1,5 @@ +#define AT_FORK_INIT_VALUE 0 +#define RESET_ATFORK_MUTEX 1 /* * tclUnixNotify.c -- * @@ -97,10 +99,11 @@ typedef struct ThreadSpecificData { * by sending this event. */ void *hwnd; /* Messaging window. */ #else /* !__CYGWIN__ */ - Tcl_Condition waitCV; /* Any other thread alerts a notifier that an + pthread_cond_t waitCV; /* Any other thread alerts a notifier that an * event is ready to be processed by signaling * this condition variable. */ #endif /* __CYGWIN__ */ + int waitCVinitialized; /* Variable to flag initialization of the structure */ int eventReady; /* True if an event is ready to be processed. * Used as condition flag together with waitCV * above. */ @@ -120,15 +123,6 @@ static Tcl_ThreadDataKey dataKey; static int notifierCount = 0; /* - * The following static stores the process ID of the initialized notifier - * thread. If it changes, we have passed a fork and we should start a new - * notifier thread. - * - * You must hold the notifierMutex lock before accessing this variable. - */ -static pid_t processIDInitialized = 0; - -/* * The following variable points to the head of a doubly-linked list of * ThreadSpecificData structures for all threads that are currently waiting on * an event. @@ -158,7 +152,15 @@ static int triggerPipe = -1; * The notifierMutex locks access to all of the global notifier state. */ -TCL_DECLARE_MUTEX(notifierMutex) +pthread_mutex_t notifierInitMutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t notifierMutex = PTHREAD_MUTEX_INITIALIZER; +/* + * The following static indicates if the notifier thread is running. + * + * You must hold the notifierInitMutex before accessing this variable. + */ + +static int notifierThreadRunning = 0; /* * The notifier thread signals the notifierCV when it has finished @@ -166,7 +168,7 @@ TCL_DECLARE_MUTEX(notifierMutex) * terminates. */ -static Tcl_Condition notifierCV; +static pthread_cond_t notifierCV = PTHREAD_COND_INITIALIZER; /* * The pollState bits @@ -194,15 +196,15 @@ static Tcl_ThreadId notifierThread; #ifdef TCL_THREADS static void NotifierThreadProc(ClientData clientData); -#if defined(HAVE_PTHREAD_ATFORK) && !defined(__APPLE__) && !defined(__hpux) -static int atForkInit = 0; +#if defined(HAVE_PTHREAD_ATFORK) +static int atForkInit = AT_FORK_INIT_VALUE; static void AtForkPrepare(void); static void AtForkParent(void); static void AtForkChild(void); #endif /* HAVE_PTHREAD_ATFORK */ #endif /* TCL_THREADS */ static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); - + /* * Import of Windows API when building threaded with Cygwin. */ @@ -251,13 +253,58 @@ extern unsigned char __stdcall ResetEvent(void *); extern unsigned char __stdcall TranslateMessage(const MSG *); /* - * Threaded-cygwin specific functions in this file: + * Threaded-cygwin specific constants and functions in this file: */ +static const WCHAR NotfyClassName[] = L"TclNotifier"; static DWORD __stdcall NotifierProc(void *hwnd, unsigned int message, void *wParam, void *lParam); #endif /* TCL_THREADS && __CYGWIN__ */ +#if TCL_THREADS +/* + *---------------------------------------------------------------------- + * + * StartNotifierThread -- + * + * Start a notfier thread and wait for the notifier pipe to be created. + * + * Results: + * None. + * + * Side effects: + * Running Thread. + * + *---------------------------------------------------------------------- + */ +static void +StartNotifierThread(const char *proc) +{ + if (!notifierThreadRunning) { + pthread_mutex_lock(¬ifierInitMutex); + if (!notifierThreadRunning) { + if (TclpThreadCreate(¬ifierThread, NotifierThreadProc, NULL, + TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) { + Tcl_Panic("%s: unable to start notifier thread", proc); + } + + pthread_mutex_lock(¬ifierMutex); + /* + * Wait for the notifier pipe to be created. + */ + + while (triggerPipe < 0) { + pthread_cond_wait(¬ifierCV, ¬ifierMutex); + } + pthread_mutex_unlock(¬ifierMutex); + + notifierThreadRunning = 1; + } + pthread_mutex_unlock(¬ifierInitMutex); + } +} +#endif /* TCL_THREADS */ + /* *---------------------------------------------------------------------- * @@ -286,13 +333,39 @@ Tcl_InitNotifier(void) tsdPtr->eventReady = 0; /* - * Start the Notifier thread if necessary. + * Initialize thread specific condition variable for this thread. */ + if (tsdPtr->waitCVinitialized == 0) { +#ifdef __CYGWIN__ + WNDCLASS class; + + class.style = 0; + class.cbClsExtra = 0; + class.cbWndExtra = 0; + class.hInstance = TclWinGetTclInstance(); + class.hbrBackground = NULL; + class.lpszMenuName = NULL; + class.lpszClassName = NotfyClassName; + class.lpfnWndProc = NotifierProc; + class.hIcon = NULL; + class.hCursor = NULL; + + RegisterClassW(&class); + tsdPtr->hwnd = CreateWindowExW(NULL, class.lpszClassName, + class.lpszClassName, 0, 0, 0, 0, 0, NULL, NULL, + TclWinGetTclInstance(), NULL); + tsdPtr->event = CreateEventW(NULL, 1 /* manual */, + 0 /* !signaled */, NULL); +#else + pthread_cond_init(&tsdPtr->waitCV, NULL); +#endif /* __CYGWIN__ */ + tsdPtr->waitCVinitialized = 1; + } - Tcl_MutexLock(¬ifierMutex); -#if defined(HAVE_PTHREAD_ATFORK) && !defined(__APPLE__) && !defined(__hpux) + pthread_mutex_lock(¬ifierInitMutex); +#if defined(HAVE_PTHREAD_ATFORK) /* - * Install pthread_atfork handlers to reinitialize the notifier in the + * Install pthread_atfork handlers to clean up the notifier in the * child of a fork. */ @@ -305,36 +378,11 @@ Tcl_InitNotifier(void) atForkInit = 1; } #endif /* HAVE_PTHREAD_ATFORK */ - /* - * Check if my process id changed, e.g. I was forked - * In this case, restart the notifier thread and close the - * pipe to the original notifier thread - */ - if (notifierCount > 0 && processIDInitialized != getpid()) { - Tcl_ConditionFinalize(¬ifierCV); - notifierCount = 0; - processIDInitialized = 0; - close(triggerPipe); - triggerPipe = -1; - } - if (notifierCount == 0) { - if (TclpThreadCreate(¬ifierThread, NotifierThreadProc, NULL, - TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) { - Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread"); - } - processIDInitialized = getpid(); - } - notifierCount++; - /* - * Wait for the notifier pipe to be created. - */ + notifierCount++; - while (triggerPipe < 0) { - Tcl_ConditionWait(¬ifierCV, ¬ifierMutex, NULL); - } + pthread_mutex_unlock(¬ifierInitMutex); - Tcl_MutexUnlock(¬ifierMutex); #endif /* TCL_THREADS */ return tsdPtr; } @@ -369,7 +417,7 @@ Tcl_FinalizeNotifier( #ifdef TCL_THREADS ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierInitMutex); notifierCount--; /* @@ -378,37 +426,25 @@ Tcl_FinalizeNotifier( */ if (notifierCount == 0) { - int result; - - if (triggerPipe < 0) { - Tcl_Panic("Tcl_FinalizeNotifier: %s", - "notifier pipe not initialized"); - } - /* - * Send "q" message to the notifier thread so that it will - * terminate. The notifier will return from its call to select() - * and notice that a "q" message has arrived, it will then close - * its side of the pipe and terminate its thread. Note the we can - * not just close the pipe and check for EOF in the notifier thread - * because if a background child process was created with exec, - * select() would not register the EOF on the pipe until the child - * processes had terminated. [Bug: 4139] [Bug: 1222872] - */ - - if (write(triggerPipe, "q", 1) != 1) { - Tcl_Panic("Tcl_FinalizeNotifier: %s", - "unable to write q to triggerPipe"); - } - close(triggerPipe); - while(triggerPipe >= 0) { - Tcl_ConditionWait(¬ifierCV, ¬ifierMutex, NULL); - } + if (triggerPipe != -1) { + if (write(triggerPipe, "q", 1) != 1) { + Tcl_Panic("Tcl_FinalizeNotifier: %s", + "unable to write q to triggerPipe"); + } + close(triggerPipe); + while(triggerPipe != -1) { + pthread_cond_wait(¬ifierCV, ¬ifierMutex); + } + if (notifierThreadRunning) { + int result = pthread_join((pthread_t) notifierThread, NULL); - result = Tcl_JoinThread(notifierThread, NULL); - if (result) { - Tcl_Panic("Tcl_FinalizeNotifier: %s", - "unable to join notifier thread"); + if (result) { + Tcl_Panic("Tcl_FinalizeNotifier: unable to join notifier " + "thread"); + } + notifierThreadRunning = 0; + } } } @@ -417,12 +453,14 @@ Tcl_FinalizeNotifier( */ #ifdef __CYGWIN__ + DestroyWindow(tsdPtr->hwnd); CloseHandle(tsdPtr->event); #else /* __CYGWIN__ */ - Tcl_ConditionFinalize(&(tsdPtr->waitCV)); + pthread_cond_destroy(&tsdPtr->waitCV); #endif /* __CYGWIN__ */ + tsdPtr->waitCVinitialized = 0; - Tcl_MutexUnlock(¬ifierMutex); + pthread_mutex_unlock(¬ifierInitMutex); #endif /* TCL_THREADS */ } } @@ -457,14 +495,15 @@ Tcl_AlertNotifier( #ifdef TCL_THREADS ThreadSpecificData *tsdPtr = clientData; - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); tsdPtr->eventReady = 1; + # ifdef __CYGWIN__ PostMessageW(tsdPtr->hwnd, 1024, 0, 0); # else - Tcl_ConditionNotify(&tsdPtr->waitCV); + pthread_cond_broadcast(&tsdPtr->waitCV); # endif /* __CYGWIN__ */ - Tcl_MutexUnlock(¬ifierMutex); + pthread_mutex_unlock(¬ifierMutex); #endif /* TCL_THREADS */ } } @@ -527,8 +566,10 @@ Tcl_ServiceModeHook( if (tclNotifierHooks.serviceModeHookProc) { tclNotifierHooks.serviceModeHookProc(mode); return; - } else { - /* Does nothing in this implementation. */ + } else if (mode == TCL_SERVICE_ALL) { +#if TCL_THREADS + StartNotifierThread("Tcl_ServiceModeHook"); +#endif } } @@ -741,6 +782,7 @@ FileHandlerEventProc( */ tsdPtr = TCL_TSD_INIT(&dataKey); + for (filePtr = tsdPtr->firstFileHandlerPtr; filePtr != NULL; filePtr = filePtr->nextPtr) { if (filePtr->fd != fileEvPtr->fd) { @@ -878,35 +920,13 @@ Tcl_WaitForEvent( #ifdef TCL_THREADS /* - * Place this thread on the list of interested threads, signal the - * notifier thread, and wait for a response or a timeout. + * Start notifier thread and place this thread on the list of + * interested threads, signal the notifier thread, and wait for a + * response or a timeout. */ + StartNotifierThread("Tcl_WaitForEvent"); -#ifdef __CYGWIN__ - if (!tsdPtr->hwnd) { - WNDCLASS class; - - class.style = 0; - class.cbClsExtra = 0; - class.cbWndExtra = 0; - class.hInstance = TclWinGetTclInstance(); - class.hbrBackground = NULL; - class.lpszMenuName = NULL; - class.lpszClassName = L"TclNotifier"; - class.lpfnWndProc = NotifierProc; - class.hIcon = NULL; - class.hCursor = NULL; - - RegisterClassW(&class); - tsdPtr->hwnd = CreateWindowExW(NULL, class.lpszClassName, - class.lpszClassName, 0, 0, 0, 0, 0, NULL, NULL, - TclWinGetTclInstance(), NULL); - tsdPtr->event = CreateEventW(NULL, 1 /* manual */, - 0 /* !signaled */, NULL); - } -#endif /* __CYGWIN */ - - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); if (timePtr != NULL && timePtr->sec == 0 && (timePtr->usec == 0 #if defined(__APPLE__) && defined(__LP64__) @@ -971,12 +991,23 @@ Tcl_WaitForEvent( } else { timeout = 0xFFFFFFFF; } - Tcl_MutexUnlock(¬ifierMutex); + pthread_mutex_unlock(¬ifierMutex); MsgWaitForMultipleObjects(1, &tsdPtr->event, 0, timeout, 1279); - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); } #else - Tcl_ConditionWait(&tsdPtr->waitCV, ¬ifierMutex, timePtr); + if (timePtr != NULL) { + Tcl_Time now; + struct timespec ptime; + + Tcl_GetTime(&now); + ptime.tv_sec = timePtr->sec + now.sec + (timePtr->usec + now.usec) / 1000000; + ptime.tv_nsec = 1000 * ((timePtr->usec + now.usec) % 1000000); + + pthread_cond_timedwait(&tsdPtr->waitCV, ¬ifierMutex, &ptime); + } else { + pthread_cond_wait(&tsdPtr->waitCV, ¬ifierMutex); + } #endif /* __CYGWIN__ */ } tsdPtr->eventReady = 0; @@ -1079,7 +1110,7 @@ Tcl_WaitForEvent( filePtr->readyMask = mask; } #ifdef TCL_THREADS - Tcl_MutexUnlock(¬ifierMutex); + pthread_mutex_unlock(¬ifierMutex); #endif /* TCL_THREADS */ return 0; } @@ -1151,15 +1182,15 @@ NotifierThreadProc( * Install the write end of the pipe into the global variable. */ - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); triggerPipe = fds[1]; /* * Signal any threads that are waiting. */ - Tcl_ConditionNotify(¬ifierCV); - Tcl_MutexUnlock(¬ifierMutex); + pthread_cond_broadcast(¬ifierCV); + pthread_mutex_unlock(¬ifierMutex); /* * Look for file events and report them to interested threads. @@ -1175,7 +1206,7 @@ NotifierThreadProc( * notifiers. */ - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); timePtr = NULL; for (tsdPtr = waitingListPtr; tsdPtr; tsdPtr = tsdPtr->nextPtr) { for (i = tsdPtr->numFdBits-1; i >= 0; --i) { @@ -1202,7 +1233,7 @@ NotifierThreadProc( timePtr = &poll; } } - Tcl_MutexUnlock(¬ifierMutex); + pthread_mutex_unlock(¬ifierMutex); /* * Set up the select mask to include the receive pipe. @@ -1226,7 +1257,7 @@ NotifierThreadProc( * Alert any threads that are waiting on a ready file descriptor. */ - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); for (tsdPtr = waitingListPtr; tsdPtr; tsdPtr = tsdPtr->nextPtr) { found = 0; @@ -1272,12 +1303,12 @@ NotifierThreadProc( } #ifdef __CYGWIN__ PostMessageW(tsdPtr->hwnd, 1024, 0, 0); -#else - Tcl_ConditionNotify(&tsdPtr->waitCV); +#else /* __CYGWIN__ */ + pthread_cond_broadcast(&tsdPtr->waitCV); #endif /* __CYGWIN__ */ } } - Tcl_MutexUnlock(¬ifierMutex); + pthread_mutex_unlock(¬ifierMutex); /* * Consume the next byte from the notifier pipe if the pipe was @@ -1306,15 +1337,15 @@ NotifierThreadProc( */ close(receivePipe); - Tcl_MutexLock(¬ifierMutex); + pthread_mutex_lock(¬ifierMutex); triggerPipe = -1; - Tcl_ConditionNotify(¬ifierCV); - Tcl_MutexUnlock(¬ifierMutex); + pthread_cond_broadcast(¬ifierCV); + pthread_mutex_unlock(¬ifierMutex); TclpThreadExit(0); } -#if defined(HAVE_PTHREAD_ATFORK) && !defined(__APPLE__) && !defined(__hpux) +#if defined(HAVE_PTHREAD_ATFORK) /* *---------------------------------------------------------------------- * @@ -1334,9 +1365,9 @@ NotifierThreadProc( static void AtForkPrepare(void) { - Tcl_MutexLock(¬ifierMutex); - TclpMasterLock(); - TclpMutexLock(); +#if RESET_ATFORK_MUTEX == 0 + pthread_mutex_lock(¬ifierInitMutex); +#endif } /* @@ -1358,9 +1389,9 @@ AtForkPrepare(void) static void AtForkParent(void) { - TclpMutexUnlock(); - TclpMasterUnlock(); - Tcl_MutexUnlock(¬ifierMutex); +#if RESET_ATFORK_MUTEX == 0 + pthread_mutex_unlock(¬ifierInitMutex); +#endif } /* @@ -1382,9 +1413,67 @@ AtForkParent(void) static void AtForkChild(void) { - TclpMutexUnlock(); - TclpMasterUnlock(); - TclMutexUnlockAndFinalize(¬ifierMutex); + if (notifierThreadRunning == 1) { + pthread_cond_destroy(¬ifierCV); + } +#if RESET_ATFORK_MUTEX == 0 + pthread_mutex_unlock(¬ifierInitMutex); +#else + pthread_mutex_init(¬ifierInitMutex, NULL); + pthread_mutex_init(¬ifierMutex, NULL); +#endif + pthread_cond_init(¬ifierCV, NULL); + + /* + * notifierThreadRunning == 1: thread is running, (there might be data in notifier lists) + * atForkInit == 0: InitNotifier was never called + * notifierCount != 0: unbalanced InitNotifier() / FinalizeNotifier calls + * waitingListPtr != 0: there are threads currently waiting for events. + */ + + if (atForkInit == 1) { + + notifierCount = 0; + if (notifierThreadRunning == 1) { + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + notifierThreadRunning = 0; + + close(triggerPipe); + triggerPipe = -1; + /* + * The waitingListPtr might contain event info from multiple + * threads, which are invalid here, so setting it to NULL is not + * unreasonable. + */ + waitingListPtr = NULL; + + /* + * The tsdPtr from before the fork is copied as well. But since + * we are paranoic, we don't trust its condvar and reset it. + */ +#ifdef __CYGWIN__ + DestroyWindow(tsdPtr->hwnd); + tsdPtr->hwnd = CreateWindowExW(NULL, NotfyClassName, + NotfyClassName, 0, 0, 0, 0, 0, NULL, NULL, + TclWinGetTclInstance(), NULL); + ResetEvent(tsdPtr->event); +#else + pthread_cond_destroy(&tsdPtr->waitCV); + pthread_cond_init(&tsdPtr->waitCV, NULL); +#endif + /* + * In case, we had multiple threads running before the fork, + * make sure, we don't try to reach out to their thread local data. + */ + tsdPtr->nextPtr = tsdPtr->prevPtr = NULL; + + /* + * The list of registered event handlers at fork time is in + * tsdPtr->firstFileHandlerPtr; + */ + } + } + Tcl_InitNotifier(); } #endif /* HAVE_PTHREAD_ATFORK */ diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index 99adbef..887689a 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -379,58 +379,6 @@ TclpMasterUnlock(void) /* *---------------------------------------------------------------------- * - * TclpMutexLock - * - * This procedure is used to grab a lock that serializes locking - * another mutex. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void -TclpMutexLock(void) -{ -#ifdef TCL_THREADS - pthread_mutex_lock(&mutexLock); -#endif -} - - -/* - *---------------------------------------------------------------------- - * - * TclpMutexUnlock - * - * This procedure is used to release a lock that serializes locking - * another mutex. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void -TclpMutexUnlock(void) -{ -#ifdef TCL_THREADS - pthread_mutex_unlock(&mutexLock); -#endif -} - - -/* - *---------------------------------------------------------------------- - * * Tcl_GetAllocMutex * * This procedure returns a pointer to a statically initialized mutex for @@ -504,17 +452,17 @@ retry: MASTER_UNLOCK; } while (1) { - TclpMutexLock(); + pthread_mutex_lock(&mutexLock); pmutexPtr = *((pthread_mutex_t **)mutexPtr); if (pmutexPtr == NULL) { - TclpMutexUnlock(); + pthread_mutex_unlock(&mutexLock); goto retry; } if (pthread_mutex_trylock(pmutexPtr) == 0) { - TclpMutexUnlock(); + pthread_mutex_unlock(&mutexLock); return; } - TclpMutexUnlock(); + pthread_mutex_unlock(&mutexLock); /* * BUGBUG: All core and Thread package tests pass when usleep() * is used; however, the Thread package tests hang at diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c index f006cca..40229f0 100644 --- a/win/tclWinThrd.c +++ b/win/tclWinThrd.c @@ -480,52 +480,6 @@ TclpMasterUnlock(void) /* *---------------------------------------------------------------------- * - * TclpMutexLock - * - * This procedure is used to grab a lock that serializes locking - * another mutex. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void -TclpMutexLock(void) -{ - EnterCriticalSection(&mutexLock); -} - -/* - *---------------------------------------------------------------------- - * - * TclpMutexUnlock - * - * This procedure is used to release a lock that serializes locking - * another mutex. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void -TclpMutexUnlock(void) -{ - LeaveCriticalSection(&mutexLock); -} - -/* - *---------------------------------------------------------------------- - * * Tcl_GetAllocMutex * * This procedure returns a pointer to a statically initialized mutex for @@ -650,17 +604,17 @@ retry: MASTER_UNLOCK; } while (1) { - TclpMutexLock(); + EnterCriticalSection(&mutexLock); csPtr = *((CRITICAL_SECTION **)mutexPtr); if (csPtr == NULL) { - TclpMutexUnlock(); + LeaveCriticalSection(&mutexLock); goto retry; } if (TryEnterCriticalSection(csPtr)) { - TclpMutexUnlock(); + LeaveCriticalSection(&mutexLock); return; } - TclpMutexUnlock(); + LeaveCriticalSection(&mutexLock); Tcl_Sleep(TCL_MUTEX_LOCK_SLEEP_TIME); } } |