Mercurial > cpython-lru_cache-weakref
diff Python/thread_os2.h @ 38794:f7d23bca599f legacy-trunk
Patch #1454481: Make thread stack size runtime tunable.
Heavily revised, comprising revisions:
46640 - original trunk revision (backed out in r46655)
46647 - markup fix (backed out in r46655)
46692:46918 merged from branch aimacintyre-sf1454481
branch tested on buildbots (Windows buildbots had problems
not related to these changes).
| author | Andrew MacIntyre <andymac@bullseye.apana.org.au> |
|---|---|
| date | Tue, 13 Jun 2006 15:04:24 +0000 |
| parents | c4587a5f5e94 |
| children | 0a4ad83fd654 |
line wrap: on
line diff
--- a/Python/thread_os2.h Tue Jun 13 12:04:43 2006 +0000 +++ b/Python/thread_os2.h Tue Jun 13 15:04:24 2006 +0000 @@ -14,10 +14,13 @@ long PyThread_get_thread_ident(void); #endif +/* default thread stack size of 64kB */ #if !defined(THREAD_STACK_SIZE) #define THREAD_STACK_SIZE 0x10000 #endif +#define OS2_STACKSIZE(x) (x ? x : THREAD_STACK_SIZE) + /* * Initialization of the C package, should not be needed. */ @@ -35,7 +38,10 @@ int aThread; int success = 0; - aThread = _beginthread(func, NULL, THREAD_STACK_SIZE, arg); + aThread = _beginthread(func, + NULL, + OS2_STACKSIZE(_pythread_stacksize), + arg); if (aThread == -1) { success = -1; @@ -275,3 +281,30 @@ DosExitCritSec(); #endif } + +/* minimum/maximum thread stack sizes supported */ +#define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ +#define THREAD_MAX_STACKSIZE 0x2000000 /* 32MB */ + +/* set the thread stack size. + * Return 0 if size is valid, -1 otherwise. + */ +static int +_pythread_os2_set_stacksize(size_t size) +{ + /* set to default */ + if (size == 0) { + _pythread_stacksize = 0; + return 0; + } + + /* valid range? */ + if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) { + _pythread_stacksize = size; + return 0; + } + + return -1; +} + +#define THREAD_SET_STACKSIZE(x) _pythread_os2_set_stacksize(x)
