Diff
Not logged in

Differences From Artifact [307d982c04]:

To Artifact [4204481d23]:


108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129









130
131
132
133
134
135
136
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145







-
+














+
+
+
+
+
+
+
+
+







    Tcl_Condition waitCV;	/* Any other thread alerts a notifier that an
				 * event is ready to be processed by signaling
				 * this condition variable. */
#endif /* __CYGWIN__ */
    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;

#ifdef TCL_THREADS
/*
 * The following static indicates the number of threads that have initialized
 * notifiers.
 *
 * You must hold the notifierMutex lock before accessing this variable.
 */

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.
 *
 * You must hold the notifierMutex lock before accessing this list.
 */
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204







-
+








/*
 * This is the thread ID of the notifier thread that does select.
 */

static Tcl_ThreadId notifierThread;

#endif
#endif /* TCL_THREADS */

/*
 * Static routines defined in this file.
 */

#ifdef TCL_THREADS
static void	NotifierThreadProc(ClientData clientData);
263
264
265
266
267
268
269











270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286
287

288
289
290
291
292
293
294
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315







+
+
+
+
+
+
+
+
+
+
+




+













-
+







    tsdPtr->eventReady = 0;

    /*
     * Start the Notifier thread if necessary.
     */

    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++;

    /*
     * Wait for the notifier pipe to be created.
     */

    while (triggerPipe < 0) {
	Tcl_ConditionWait(&notifierCV, &notifierMutex, NULL);
    }

    Tcl_MutexUnlock(&notifierMutex);
#endif
#endif /* TCL_THREADS */
    return (ClientData) tsdPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_FinalizeNotifier --