1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
-
+
|
/*
* tclUnixThrd.c --
*
* This file implements the UNIX-specific thread support.
*
* Copyright (c) 1991-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* Copyright (c) 2008 by George Peter Staplin
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclUnixThrd.c,v 1.59 2008/07/24 21:54:42 nijtmans Exp $
* RCS: @(#) $Id: tclUnixThrd.c,v 1.60 2008/08/13 23:08:39 das Exp $
*/
#include "tclInt.h"
#ifdef TCL_THREADS
#include "pthread.h"
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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
295
296
297
298
299
300
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
void
TclpThreadExit(
int status)
{
pthread_exit(INT2PTR(status));
}
#endif /* TCL_THREADS */
#ifdef TCL_THREADS
/*
*----------------------------------------------------------------------
*
* TclpThreadGetStackSize --
*
* This procedure returns the size of the current thread's stack.
*
* Results:
* Stack size (in bytes?) or -1 for error or 0 for undeterminable.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
size_t
TclpThreadGetStackSize(void)
{
size_t stackSize = 0;
#if defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && defined(TclpPthreadGetAttrs)
pthread_attr_t threadAttr; /* This will hold the thread attributes for
* the current thread. */
#ifdef __GLIBC__
/*
* Fix for [Bug 1815573]
*
* DESCRIPTION:
* On linux TclpPthreadGetAttrs (which is pthread_attr_get_np) may return
* bogus values on the initial thread.
*
* ASSUMPTIONS:
* There seems to be no api to determine if we are on the initial
* thread. The simple scheme implemented here assumes:
* 1. The first Tcl interp to be created lives in the initial thread. If
* this assumption is not true, the fix is to call
* TclpThreadGetStackSize from the initial thread previous to
* creating any Tcl interpreter. In this case, especially if another
* Tcl interpreter may be created in the initial thread, it might be
* better to enable the second branch in the #if below
* 2. There will be no races in creating the first Tcl interp - ie, the
* second Tcl interp will be created only after the first call to
* Tcl_CreateInterp returns.
*
* These assumptions are satisfied by tclsh. Embedders on linux may want
* to check their validity, and possibly adapt the code on failing to meet
* them.
*/
static int initialized = 0;
if (!initialized) {
initialized = 1;
return 0;
} else {
#else
{
#endif
if (pthread_attr_init(&threadAttr) != 0) {
return -1;
}
if (TclpPthreadGetAttrs(pthread_self(), &threadAttr) != 0) {
pthread_attr_destroy(&threadAttr);
return (size_t)-1;
}
}
if (pthread_attr_getstacksize(&threadAttr, &stackSize) != 0) {
pthread_attr_destroy(&threadAttr);
return (size_t)-1;
}
pthread_attr_destroy(&threadAttr);
#elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP)
#ifdef __APPLE__
/*
* On Darwin, the API below does not return the correct stack size for the
* main thread (which is not a real pthread), so fallback to getrlimit().
*/
if (!pthread_main_np())
#endif
stackSize = pthread_get_stacksize_np(pthread_self());
#else
/*
* Cannot determine the real stack size of this thread. The caller might
* want to try looking at the process accounting limits instead.
*/
#endif
return stackSize;
}
#endif /* TCL_THREADS */
/*
*----------------------------------------------------------------------
*
* Tcl_GetCurrentThread --
*
|