diff options
| author | donal.k.fellows@manchester.ac.uk <dkf> | 2004-06-23 00:24:31 (GMT) |
|---|---|---|
| committer | donal.k.fellows@manchester.ac.uk <dkf> | 2004-06-23 00:24:31 (GMT) |
| commit | 692b6ceda56db0b788c36c86875634466699a5fd (patch) | |
| tree | 5a154848a1901797f909f029933e19ccdb283c63 /unix/tclUnixThrd.c | |
| parent | 6c8787f0a1abf1dfcc22fba700fa11ceca91180f (diff) | |
| download | tcl-692b6ceda56db0b788c36c86875634466699a5fd.zip tcl-692b6ceda56db0b788c36c86875634466699a5fd.tar.gz tcl-692b6ceda56db0b788c36c86875634466699a5fd.tar.bz2 | |
Version of [Patch 746578] that works with Linux and is likely to work elsewhere
Diffstat (limited to 'unix/tclUnixThrd.c')
| -rw-r--r-- | unix/tclUnixThrd.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index 297fc3b..ef06dee 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -199,6 +199,55 @@ TclpThreadExit(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. + * + *---------------------------------------------------------------------- + */ + +int +TclpThreadGetStackSize() +{ +#if defined(HAVE_PTHREAD_SETSTACKSIZE) && defined(TclpPthreadGetAttrs) + pthread_attr_t threadAttr; /* This will hold the thread attributes for + * the current thread. */ + size_t stackSize; + + if (pthread_attr_init(&threadAttr) != 0) { + return -1; + } + if (TclpPthreadGetAttrs(pthread_self(), &threadAttr) != 0) { + pthread_attr_destroy(&threadAttr); + return -1; + } + if (pthread_attr_getstacksize(&threadAttr, &stackSize) != 0) { + pthread_attr_destroy(&threadAttr); + return -1; + } + pthread_attr_destroy(&threadAttr); + return (int) stackSize; +#else + /* + * Cannot determine the real stack size of this thread. The + * caller might want to try looking at the process accounting + * limits instead. + */ + return 0; +#endif +} +#endif /* TCL_THREADS */ + /* *---------------------------------------------------------------------- * |
