summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixThrd.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-06-23 00:24:31 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-06-23 00:24:31 (GMT)
commit32d847fdb1dab403a2db715367cceadad9f9e467 (patch)
tree5a154848a1901797f909f029933e19ccdb283c63 /unix/tclUnixThrd.c
parent02be87df7fbd313cca35b5461372f13152ac7131 (diff)
downloadtcl-32d847fdb1dab403a2db715367cceadad9f9e467.zip
tcl-32d847fdb1dab403a2db715367cceadad9f9e467.tar.gz
tcl-32d847fdb1dab403a2db715367cceadad9f9e467.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.c49
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 */
+
/*
*----------------------------------------------------------------------
*