summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--include/apr_thread_proc.h8
-rw-r--r--include/arch/os2/apr_arch_threadproc.h1
-rw-r--r--include/arch/win32/apr_arch_threadproc.h1
-rw-r--r--threadproc/beos/thread.c6
-rw-r--r--threadproc/netware/thread.c7
-rw-r--r--threadproc/os2/thread.c12
-rw-r--r--threadproc/unix/thread.c16
-rw-r--r--threadproc/win32/thread.c16
9 files changed, 67 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 2e8d88e2f..5102f17a9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,10 @@ Changes for APR 1.1 [Deferring these features when 1.0 is rolled out.]
Changes with APR 1.0
+ *) Add apr_threadattr_stacksize_set() for overriding the default
+ stack size for threads created by apr_thread_create().
+ [Jeff Trawick]
+
*) The whole codebase was relicensed and is now available under
the Apache License, Version 2.0 (http://www.apache.org/licenses).
[Apache Software Foundation]
diff --git a/include/apr_thread_proc.h b/include/apr_thread_proc.h
index 539ac471d..ce793f6d2 100644
--- a/include/apr_thread_proc.h
+++ b/include/apr_thread_proc.h
@@ -216,6 +216,14 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
/**
+ * Set the stack size of newly created threads.
+ * @param attr The threadattr to affect
+ * @param on The stack size in bytes
+ */
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+ apr_size_t stacksize);
+
+/**
* Create a new thread of execution
* @param new_thread The newly created thread handle.
* @param attr The threadattr to use to determine how to create the thread
diff --git a/include/arch/os2/apr_arch_threadproc.h b/include/arch/os2/apr_arch_threadproc.h
index f61eb4938..2efc4d32b 100644
--- a/include/arch/os2/apr_arch_threadproc.h
+++ b/include/arch/os2/apr_arch_threadproc.h
@@ -27,6 +27,7 @@
struct apr_threadattr_t {
apr_pool_t *pool;
unsigned long attr;
+ apr_size_t stacksize;
};
struct apr_thread_t {
diff --git a/include/arch/win32/apr_arch_threadproc.h b/include/arch/win32/apr_arch_threadproc.h
index f4903f0f1..6e8ac8d54 100644
--- a/include/arch/win32/apr_arch_threadproc.h
+++ b/include/arch/win32/apr_arch_threadproc.h
@@ -35,6 +35,7 @@ struct apr_thread_t {
struct apr_threadattr_t {
apr_pool_t *pool;
apr_int32_t detach;
+ apr_size_t stacksize;
};
struct apr_threadkey_t {
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c
index 80ec13a6d..15f1ca091 100644
--- a/threadproc/beos/thread.c
+++ b/threadproc/beos/thread.c
@@ -49,6 +49,12 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
return APR_NOTDETACH;
}
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+ apr_size_t stacksize)
+{
+ return APR_ENOTIMPL;
+}
+
static void *dummy_worker(void *opaque)
{
apr_thread_t *thd = (apr_thread_t*)opaque;
diff --git a/threadproc/netware/thread.c b/threadproc/netware/thread.c
index 374b0d339..1703b55b1 100644
--- a/threadproc/netware/thread.c
+++ b/threadproc/netware/thread.c
@@ -50,6 +50,13 @@ apr_status_t apr_threadattr_detach_get(apr_threadattr_t *attr)
return APR_NOTDETACH;
}
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+ apr_size_t stacksize)
+{
+ attr->stack_size = stacksize;
+ return APR_SUCCESS;
+}
+
static void *dummy_worker(void *opaque)
{
apr_thread_t *thd = (apr_thread_t *)opaque;
diff --git a/threadproc/os2/thread.c b/threadproc/os2/thread.c
index d9cc23210..24b29f680 100644
--- a/threadproc/os2/thread.c
+++ b/threadproc/os2/thread.c
@@ -33,6 +33,7 @@ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, apr_pool
(*new)->pool = pool;
(*new)->attr = 0;
+ (*new)->stacksize = 0;
return APR_SUCCESS;
}
@@ -51,7 +52,12 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
return (attr->attr & APR_THREADATTR_DETACHED) ? APR_DETACH : APR_NOTDETACH;
}
-
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+ apr_size_t stacksize)
+{
+ attr->stacksize = stacksize;
+ return APR_SUCCESS;
+}
static void apr_thread_begin(void *arg)
{
@@ -94,7 +100,9 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t
}
thread->tid = _beginthread(apr_thread_begin, NULL,
- APR_THREAD_STACKSIZE, thread);
+ thread->attr->stacksize > 0 ?
+ thread->attr->stacksize : APR_THREAD_STACKSIZE,
+ thread);
if (thread->tid < 0) {
return errno;
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index 6997e75df..00eee7ea3 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -78,6 +78,22 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
return APR_NOTDETACH;
}
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+ apr_size_t stacksize)
+{
+ int stat;
+
+ stat = pthread_attr_setstacksize(&attr->attr, stacksize);
+ if (stat == 0) {
+ return APR_SUCCESS;
+ }
+#ifdef PTHREAD_SETS_ERRNO
+ stat = errno;
+#endif
+
+ return stat;
+}
+
static void *dummy_worker(void *opaque)
{
apr_thread_t *thread = (apr_thread_t*)opaque;
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index da36c3d83..92b6755a6 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -38,6 +38,9 @@ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
}
(*new)->pool = pool;
+ (*new)->detach = 0;
+ (*new)->stacksize = 0;
+
return APR_SUCCESS;
}
@@ -55,6 +58,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
return APR_NOTDETACH;
}
+APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
+ apr_size_t stacksize)
+{
+ attr->stacksize = stacksize;
+ return APR_SUCCESS;
+}
+
static void *dummy_worker(void *opaque)
{
apr_thread_t *thd = (apr_thread_t *)opaque;
@@ -89,13 +99,15 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
* same size as the calling thread.
*/
#ifndef _WIN32_WCE
- if (((*new)->td = (HANDLE)_beginthreadex(NULL, 0,
+ if (((*new)->td = (HANDLE)_beginthreadex(NULL,
+ attr && attr->stacksize > 0 ? attr->stacksize : 0,
(unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
(*new), 0, &temp)) == 0) {
return APR_FROM_OS_ERROR(_doserrno);
}
#else
- if (((*new)->td = CreateThread(NULL, 0,
+ if (((*new)->td = CreateThread(NULL,
+ attr && attr->stacksize > 0 ? attr->stacksize : 0,
(unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
(*new), 0, &temp)) == 0) {
return apr_get_os_error();