summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2005-01-19 21:51:07 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2005-01-19 21:51:07 +0000
commita8b37f7c9a6f8380c5b03d222ce43269d9e59cd7 (patch)
tree61c82cb1b363eba844a799968eb799f08477e478
parenta07aeff21795a11b98404270feecf7410370c03f (diff)
downloadlibapr-a8b37f7c9a6f8380c5b03d222ce43269d9e59cd7.tar.gz
grab this feature from APR >= 1.0:
Add apr_threadattr_stacksize_set() for overriding the default stack size for threads created by apr_thread_create(). git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x@125670 13f79535-47bb-0310-9956-ffa450edef68
-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.c16
-rw-r--r--threadproc/unix/thread.c16
-rw-r--r--threadproc/win32/thread.c14
9 files changed, 69 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index f4aff7689..5ce1d5536 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
Changes with APR 0.9.6
+ *) Add apr_threadattr_stacksize_set() for overriding the default
+ stack size for threads created by apr_thread_create().
+ [Jeff Trawick]
+
*) Add an RPM spec file. [Graham Leggett]
*) Add a build script to create a solaris package. [Graham Leggett]
diff --git a/include/apr_thread_proc.h b/include/apr_thread_proc.h
index 231e7b54b..8faeea983 100644
--- a/include/apr_thread_proc.h
+++ b/include/apr_thread_proc.h
@@ -219,6 +219,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 stacksize 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 e72bd916d..f752fd7df 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 d3229b17b..28c0a14e9 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..16a179cf2 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;
}
@@ -53,6 +54,15 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
+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)
{
apr_thread_t *thread = (apr_thread_t *)arg;
@@ -93,8 +103,10 @@ 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->tid = _beginthread(apr_thread_begin, NULL,
+ 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 bf9645f31..4df4a9f1c 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -82,6 +82,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 fff81f221..16925e2df 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -39,6 +39,7 @@ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
(*new)->pool = pool;
(*new)->detach = 0;
+ (*new)->stacksize = 0;
return APR_SUCCESS;
}
@@ -57,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;
@@ -93,13 +101,15 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
* same size as the calling thread.
*/
#ifndef _WIN32_WCE
- if ((handle = (HANDLE)_beginthreadex(NULL, 0,
+ if ((handle = (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 ((handle = CreateThread(NULL, 0,
+ if ((handle = 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();