diff options
author | Andrew MacIntyre <andymac@bullseye.apana.org.au> | 2006-06-13 15:04:24 +0000 |
---|---|---|
committer | Andrew MacIntyre <andymac@bullseye.apana.org.au> | 2006-06-13 15:04:24 +0000 |
commit | 9291332de137141057591386b4ba449ae3a5ed48 (patch) | |
tree | 31e4a0a2411052ceb8e05284fe9409c6995f79ca /Python/thread_nt.h | |
parent | c6f5b3ad6c9e93235f9aa53d1ed8086030fbcd6c (diff) | |
download | cpython-git-9291332de137141057591386b4ba449ae3a5ed48.tar.gz |
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).
Diffstat (limited to 'Python/thread_nt.h')
-rw-r--r-- | Python/thread_nt.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/Python/thread_nt.h b/Python/thread_nt.h index 4dc6d6c313..67f5ed5174 100644 --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -196,7 +196,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) if (obj.done == NULL) return -1; - rv = _beginthread(bootstrap, 0, &obj); /* use default stack size */ + rv = _beginthread(bootstrap, _pythread_stacksize, &obj); if (rv == (Py_uintptr_t)-1) { /* I've seen errno == EAGAIN here, which means "there are * too many threads". @@ -335,3 +335,30 @@ PyThread_release_lock(PyThread_type_lock aLock) if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError())); } + +/* minimum/maximum thread stack sizes supported */ +#define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ +#define THREAD_MAX_STACKSIZE 0x10000000 /* 256MB */ + +/* set the thread stack size. + * Return 0 if size is valid, -1 otherwise. + */ +static int +_pythread_nt_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_nt_set_stacksize(x) |