summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixNotfy.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2013-07-21 14:52:57 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2013-07-21 14:52:57 (GMT)
commit4f645e7d24cb24959ae8aea7b54297b421d506f5 (patch)
tree3c6af0716f2bff72cada3681baaa8a464c06e259 /unix/tclUnixNotfy.c
parentae8d32e17d3ddc932def49dc45643928d7fe97ea (diff)
parent6b9dcf87ecc79d795e79e3d6d8e03b894f36a6cc (diff)
downloadtcl-4f645e7d24cb24959ae8aea7b54297b421d506f5.zip
tcl-4f645e7d24cb24959ae8aea7b54297b421d506f5.tar.gz
tcl-4f645e7d24cb24959ae8aea7b54297b421d506f5.tar.bz2
Rebase to core-8-5-branch
Add "testfork" test command to be usable in testcase.
Diffstat (limited to 'unix/tclUnixNotfy.c')
-rw-r--r--unix/tclUnixNotfy.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c
index 51f0b1f..88e290e 100644
--- a/unix/tclUnixNotfy.c
+++ b/unix/tclUnixNotfy.c
@@ -112,7 +112,7 @@ typedef struct ThreadSpecificData {
int eventReady; /* True if an event is ready to be processed.
* Used as condition flag together with waitCV
* above. */
-#endif
+#endif /* TCL_THREADS */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
@@ -128,6 +128,15 @@ 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.
@@ -185,7 +194,7 @@ static Tcl_Condition notifierCV;
static Tcl_ThreadId notifierThread;
-#endif
+#endif /* TCL_THREADS */
/*
* Static routines defined in this file.
@@ -267,10 +276,22 @@ Tcl_InitNotifier(void)
*/
Tcl_MutexLock(&notifierMutex);
+ /*
+ * 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()) {
+ notifierCount = 0;
+ processIDInitialized = 0;
+ close(triggerPipe);
+ triggerPipe = -1;
+ }
if (notifierCount == 0) {
if (TclpThreadCreate(&notifierThread, NotifierThreadProc, NULL,
TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) {
Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread");
+ processIDInitialized = getpid();
}
}
notifierCount++;
@@ -284,7 +305,7 @@ Tcl_InitNotifier(void)
}
Tcl_MutexUnlock(&notifierMutex);
-#endif
+#endif /* TCL_THREADS */
return (ClientData) tsdPtr;
}