summaryrefslogtreecommitdiff
path: root/threadproc
diff options
context:
space:
mode:
authorstriker <striker@13f79535-47bb-0310-9956-ffa450edef68>2002-03-19 18:31:08 +0000
committerstriker <striker@13f79535-47bb-0310-9956-ffa450edef68>2002-03-19 18:31:08 +0000
commitd380276b3d3719501300ead9ee97ce90bb7a0eb9 (patch)
tree2f1c13fc590488eb405f31ca1ec32c18ba037394 /threadproc
parentde84b53cdbb5340e0b0038eb562aac24342619cb (diff)
downloadlibapr-d380276b3d3719501300ead9ee97ce90bb7a0eb9.tar.gz
Style Police writes some more tickets...
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63159 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r--threadproc/unix/proc.c139
-rw-r--r--threadproc/unix/thread.c58
-rw-r--r--threadproc/unix/threadpriv.c41
3 files changed, 158 insertions, 80 deletions
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c
index 3c71c4e23..b0f41fd1f 100644
--- a/threadproc/unix/proc.c
+++ b/threadproc/unix/proc.c
@@ -57,7 +57,8 @@
#include "apr_portable.h"
#include "apr_signal.h"
-APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new,
+ apr_pool_t *pool)
{
(*new) = (apr_procattr_t *)apr_pcalloc(pool, sizeof(apr_procattr_t));
@@ -69,15 +70,18 @@ APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t in,
- apr_int32_t out, apr_int32_t err)
+APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
+ apr_int32_t in,
+ apr_int32_t out,
+ apr_int32_t err)
{
apr_status_t status;
if (in != 0) {
- if ((status = apr_file_pipe_create(&attr->child_in, &attr->parent_in,
- attr->pool)) != APR_SUCCESS) {
+ if ((status = apr_file_pipe_create(&attr->child_in, &attr->parent_in,
+ attr->pool)) != APR_SUCCESS) {
return status;
}
+
switch (in) {
case APR_FULL_BLOCK:
break;
@@ -91,12 +95,14 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t
apr_file_pipe_timeout_set(attr->child_in, 0);
apr_file_pipe_timeout_set(attr->parent_in, 0);
}
- }
+ }
+
if (out) {
- if ((status = apr_file_pipe_create(&attr->parent_out, &attr->child_out,
- attr->pool)) != APR_SUCCESS) {
+ if ((status = apr_file_pipe_create(&attr->parent_out, &attr->child_out,
+ attr->pool)) != APR_SUCCESS) {
return status;
}
+
switch (out) {
case APR_FULL_BLOCK:
break;
@@ -110,12 +116,14 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t
apr_file_pipe_timeout_set(attr->child_out, 0);
apr_file_pipe_timeout_set(attr->parent_out, 0);
}
- }
+ }
+
if (err) {
- if ((status = apr_file_pipe_create(&attr->parent_err, &attr->child_err,
- attr->pool)) != APR_SUCCESS) {
+ if ((status = apr_file_pipe_create(&attr->parent_err, &attr->child_err,
+ attr->pool)) != APR_SUCCESS) {
return status;
}
+
switch (err) {
case APR_FULL_BLOCK:
break;
@@ -129,12 +137,14 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t
apr_file_pipe_timeout_set(attr->child_err, 0);
apr_file_pipe_timeout_set(attr->parent_err, 0);
}
- }
+ }
+
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, apr_file_t *child_in,
+APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr,
+ apr_file_t *child_in,
apr_file_t *parent_in)
{
if (attr->child_in == NULL && attr->parent_in == NULL)
@@ -150,7 +160,8 @@ APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, apr_fi
}
-APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_file_t *child_out,
+APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr,
+ apr_file_t *child_out,
apr_file_t *parent_out)
{
if (attr->child_out == NULL && attr->parent_out == NULL)
@@ -166,7 +177,8 @@ APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_f
}
-APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_file_t *child_err,
+APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr,
+ apr_file_t *child_err,
apr_file_t *parent_err)
{
if (attr->child_err == NULL && attr->parent_err == NULL)
@@ -182,25 +194,26 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_f
}
-APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
- const char *dir)
+APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
+ const char *dir)
{
attr->currdir = apr_pstrdup(attr->pool, dir);
if (attr->currdir) {
return APR_SUCCESS;
}
+
return APR_ENOMEM;
}
APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
- apr_cmdtype_e cmd)
+ apr_cmdtype_e cmd)
{
attr->cmdtype = cmd;
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
- apr_int32_t detach)
+APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
+ apr_int32_t detach)
{
attr->detached = detach;
return APR_SUCCESS;
@@ -209,21 +222,24 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
{
int pid;
-
+
if ((pid = fork()) < 0) {
return errno;
}
else if (pid == 0) {
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
+
return APR_INCHILD;
}
+
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
+
return APR_INPARENT;
}
@@ -272,10 +288,12 @@ static apr_status_t limit_proc(apr_procattr_t *attr)
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
+APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
+ const char *progname,
const char * const *args,
const char * const *env,
- apr_procattr_t *attr, apr_pool_t *pool)
+ apr_procattr_t *attr,
+ apr_pool_t *pool)
{
int i;
const char **newargs;
@@ -283,16 +301,17 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
new->in = attr->parent_in;
new->err = attr->parent_err;
new->out = attr->parent_out;
+
if ((new->pid = fork()) < 0) {
return errno;
}
- else if (new->pid == 0) {
+ else if (new->pid == 0) {
int status;
/* child process */
/*
- * If we do exec cleanup before the dup2() calls to set up pipes
- * on 0-2, we accidentally close the pipes used by programs like
+ * If we do exec cleanup before the dup2() calls to set up pipes
+ * on 0-2, we accidentally close the pipes used by programs like
* mod_cgid.
*
* If we do exec cleanup after the dup2() calls, cleanup can accidentally
@@ -304,13 +323,15 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
*/
if (attr->child_in) {
- apr_pool_cleanup_kill(apr_file_pool_get(attr->child_in),
+ apr_pool_cleanup_kill(apr_file_pool_get(attr->child_in),
attr->child_in, apr_unix_file_cleanup);
}
+
if (attr->child_out) {
apr_pool_cleanup_kill(apr_file_pool_get(attr->child_out),
attr->child_out, apr_unix_file_cleanup);
}
+
if (attr->child_err) {
apr_pool_cleanup_kill(apr_file_pool_get(attr->child_err),
attr->child_err, apr_unix_file_cleanup);
@@ -323,18 +344,20 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
dup2(attr->child_in->filedes, STDIN_FILENO);
apr_file_close(attr->child_in);
}
+
if (attr->child_out) {
apr_file_close(attr->parent_out);
dup2(attr->child_out->filedes, STDOUT_FILENO);
apr_file_close(attr->child_out);
}
+
if (attr->child_err) {
apr_file_close(attr->parent_err);
dup2(attr->child_err->filedes, STDERR_FILENO);
apr_file_close(attr->child_err);
}
-
- apr_signal(SIGCHLD, SIG_DFL); /*not sure if this is needed or not */
+
+ apr_signal(SIGCHLD, SIG_DFL); /* not sure if this is needed or not */
if (attr->currdir != NULL) {
if (chdir(attr->currdir) == -1) {
@@ -351,31 +374,37 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
while (args[i]) {
i++;
}
- newargs =
- (const char **) apr_palloc(pool, sizeof (char *) * (i + 3));
+
+ newargs = (const char **)apr_palloc(pool, sizeof (char *) * (i + 3));
newargs[0] = SHELL_PATH;
newargs[1] = "-c";
+
i = 0;
while (args[i]) {
- newargs[i + 2] = args[i];
+ newargs[i + 2] = args[i];
i++;
}
+
newargs[i + 2] = NULL;
+
if (attr->detached) {
apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
}
+
execve(SHELL_PATH, (char * const *) newargs, (char * const *)env);
}
else if (attr->cmdtype == APR_PROGRAM) {
if (attr->detached) {
apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
}
+
execve(progname, (char * const *)args, (char * const *)env);
}
else if (attr->cmdtype == APR_PROGRAM_ENV) {
if (attr->detached) {
apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
}
+
execv(progname, (char * const *)args);
}
else {
@@ -383,35 +412,40 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
if (attr->detached) {
apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
}
+
execvp(progname, (char * const *)args);
}
- exit(-1); /* if we get here, there is a problem, so exit with an */
- /* error code. */
+ exit(-1); /* if we get here, there is a problem, so exit with an
+ * error code. */
}
+
/* Parent process */
if (attr->child_in) {
apr_file_close(attr->child_in);
}
+
if (attr->child_out) {
apr_file_close(attr->child_out);
}
+
if (attr->child_err) {
apr_file_close(attr->child_err);
}
+
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
+APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
int *exitcode,
apr_exit_why_e *exitwhy,
- apr_wait_how_e waithow,
+ apr_wait_how_e waithow,
apr_pool_t *p)
{
proc->pid = -1;
return apr_proc_wait(proc, exitcode, exitwhy, waithow);
-}
+}
-APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
+APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
int *exitcode, apr_exit_why_e *exitwhy,
apr_wait_how_e waithow)
{
@@ -424,6 +458,7 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
if (exitcode == NULL) {
exitcode = &ignore;
}
+
if (exitwhy == NULL) {
exitwhy = &ignorewhy;
}
@@ -431,35 +466,41 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
if (waithow != APR_WAIT) {
waitpid_options |= WNOHANG;
}
-
+
if ((pstatus = waitpid(proc->pid, &exit_int, waitpid_options)) > 0) {
proc->pid = pstatus;
+
if (WIFEXITED(exit_int)) {
*exitwhy = APR_PROC_EXIT;
*exitcode = WEXITSTATUS(exit_int);
}
else if (WIFSIGNALED(exit_int)) {
*exitwhy = APR_PROC_SIGNAL;
+
#ifdef WCOREDUMP
if (WCOREDUMP(exit_int)) {
*exitwhy |= APR_PROC_SIGNAL_CORE;
}
#endif
+
*exitcode = WTERMSIG(exit_int);
}
else {
/* unexpected condition */
return APR_EGENERAL;
}
+
return APR_CHILD_DONE;
}
else if (pstatus == 0) {
return APR_CHILD_NOTDONE;
}
+
return errno;
-}
+}
-APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32_t what,
+APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
+ apr_int32_t what,
struct rlimit *limit)
{
switch(what) {
@@ -470,6 +511,7 @@ APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32
#else
return APR_ENOTIMPL;
#endif
+
case APR_LIMIT_MEM:
#if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
attr->limit_mem = limit;
@@ -477,6 +519,7 @@ APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32
#else
return APR_ENOTIMPL;
#endif
+
case APR_LIMIT_NPROC:
#ifdef RLIMIT_NPROC
attr->limit_nproc = limit;
@@ -484,6 +527,8 @@ APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32
#else
return APR_ENOTIMPL;
#endif
+
}
+
return APR_SUCCESS;
}
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index 1c5df14cb..693396d99 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -59,10 +59,11 @@
#if APR_HAS_THREADS
#if APR_HAVE_PTHREAD_H
-APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
+ apr_pool_t *pool)
{
apr_status_t stat;
-
+
(*new) = (apr_threadattr_t *)apr_pcalloc(pool, sizeof(apr_threadattr_t));
(*new)->attr = (pthread_attr_t *)apr_pcalloc(pool, sizeof(pthread_attr_t));
@@ -79,10 +80,12 @@ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, apr_pool
#ifdef PTHREAD_SETS_ERRNO
stat = errno;
#endif
+
return stat;
}
-APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, apr_int32_t on)
+APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
+ apr_int32_t on)
{
apr_status_t stat;
#ifdef PTHREAD_ATTR_SETDETACHSTATE_ARG2_ADDR
@@ -92,12 +95,14 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, apr_
#else
if ((stat = pthread_attr_setdetachstate(attr->attr, on)) == 0) {
#endif
+
return APR_SUCCESS;
}
else {
#ifdef PTHREAD_SETS_ERRNO
stat = errno;
#endif
+
return stat;
}
}
@@ -122,13 +127,15 @@ static void *dummy_worker(void *opaque)
return thread->func(thread, thread->data);
}
-APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr,
- apr_thread_start_t func, void *data,
+APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
+ apr_threadattr_t *attr,
+ apr_thread_start_t func,
+ void *data,
apr_pool_t *pool)
{
apr_status_t stat;
pthread_attr_t *temp;
-
+
(*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
if ((*new) == NULL) {
@@ -144,7 +151,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t
(*new)->pool = pool;
(*new)->data = data;
(*new)->func = func;
-
+
if (attr)
temp = attr->attr;
else
@@ -162,8 +169,9 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t
#ifdef PTHREAD_SETS_ERRNO
stat = errno;
#endif
+
return stat;
- }
+ }
}
APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
@@ -171,12 +179,14 @@ APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
return pthread_self();
}
-APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1, apr_os_thread_t tid2)
+APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
+ apr_os_thread_t tid2)
{
return pthread_equal(tid1, tid2);
}
-APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval)
+APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
+ apr_status_t retval)
{
thd->exitval = retval;
apr_pool_destroy(thd->pool);
@@ -184,7 +194,8 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *thd)
+APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
+ apr_thread_t *thd)
{
apr_status_t stat;
apr_status_t *thread_stat;
@@ -197,6 +208,7 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *th
#ifdef PTHREAD_SETS_ERRNO
stat = errno;
#endif
+
return stat;
}
}
@@ -210,12 +222,14 @@ APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
#else
if ((stat = pthread_detach(*thd->td)) == 0) {
#endif
+
return APR_SUCCESS;
}
else {
#ifdef PTHREAD_SETS_ERRNO
stat = errno;
#endif
+
return stat;
}
}
@@ -224,34 +238,39 @@ void apr_thread_yield()
{
}
-APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key, apr_thread_t *thread)
+APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
+ apr_thread_t *thread)
{
return apr_pool_userdata_get(data, key, thread->pool);
}
APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
- apr_status_t (*cleanup) (void *),
+ apr_status_t (*cleanup)(void *),
apr_thread_t *thread)
{
return apr_pool_userdata_set(data, key, cleanup, thread->pool);
}
-APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd, apr_thread_t *thd)
+APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd,
+ apr_thread_t *thd)
{
*thethd = thd->td;
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, apr_os_thread_t *thethd,
- apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd,
+ apr_os_thread_t *thethd,
+ apr_pool_t *pool)
{
if (pool == NULL) {
return APR_ENOPOOL;
}
+
if ((*thd) == NULL) {
(*thd) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
(*thd)->pool = pool;
}
+
(*thd)->td = thethd;
return APR_SUCCESS;
}
@@ -266,7 +285,7 @@ APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
void (*func)(void))
{
return pthread_once(&control->once, func);
@@ -279,9 +298,10 @@ APR_POOL_IMPLEMENT_ACCESSOR(thread)
#if !APR_HAS_THREADS
-APR_DECLARE(apr_status_t) apr_os_thread_get(void); /* avoid warning for no prototype */
+/* avoid warning for no prototype */
+APR_DECLARE(apr_status_t) apr_os_thread_get(void);
-APR_DECLARE(apr_status_t) apr_os_thread_get(void)
+APR_DECLARE(apr_status_t) apr_os_thread_get(void)
{
return APR_ENOTIMPL;
}
diff --git a/threadproc/unix/threadpriv.c b/threadproc/unix/threadpriv.c
index 2e11bfcb7..e1d928701 100644
--- a/threadproc/unix/threadpriv.c
+++ b/threadproc/unix/threadpriv.c
@@ -59,8 +59,9 @@
#if APR_HAS_THREADS
#if APR_HAVE_PTHREAD_H
-APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
- void (*dest)(void *), apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
+ void (*dest)(void *),
+ apr_pool_t *pool)
{
(*key) = (apr_threadkey_t *)apr_pcalloc(pool, sizeof(apr_threadkey_t));
@@ -74,20 +75,23 @@ APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
}
-APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new, apr_threadkey_t *key)
+APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new,
+ apr_threadkey_t *key)
{
#ifdef PTHREAD_GETSPECIFIC_TAKES_TWO_ARGS
if (pthread_getspecific(key->key,new))
*new = NULL;
-#else
+#else
(*new) = pthread_getspecific(key->key);
#endif
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, apr_threadkey_t *key)
+APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
+ apr_threadkey_t *key)
{
apr_status_t stat;
+
if ((stat = pthread_setspecific(key->key, priv)) == 0) {
return APR_SUCCESS;
}
@@ -100,53 +104,62 @@ APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, apr_threadkey_t
APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key)
{
apr_status_t stat;
+
if ((stat = pthread_key_delete(key->key)) == 0) {
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
+
return stat;
}
#endif
APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
- apr_threadkey_t *threadkey)
+ apr_threadkey_t *threadkey)
{
return apr_pool_userdata_get(data, key, threadkey->pool);
}
APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
- apr_status_t (*cleanup) (void *),
- apr_threadkey_t *threadkey)
+ apr_status_t (*cleanup)(void *),
+ apr_threadkey_t *threadkey)
{
return apr_pool_userdata_set(data, key, cleanup, threadkey->pool);
}
-APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey, apr_threadkey_t *key)
+APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey,
+ apr_threadkey_t *key)
{
*thekey = key->key;
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
- apr_os_threadkey_t *thekey, apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
+ apr_os_threadkey_t *thekey,
+ apr_pool_t *pool)
{
if (pool == NULL) {
return APR_ENOPOOL;
}
+
if ((*key) == NULL) {
(*key) = (apr_threadkey_t *)apr_pcalloc(pool, sizeof(apr_threadkey_t));
(*key)->pool = pool;
}
+
(*key)->key = *thekey;
return APR_SUCCESS;
-}
+}
#endif /* APR_HAVE_PTHREAD_H */
#endif /* APR_HAS_THREADS */
#if !APR_HAS_THREADS
-APR_DECLARE(apr_status_t) apr_os_threadkey_get(void); /* avoid warning for no prototype */
+
+/* avoid warning for no prototype */
+APR_DECLARE(apr_status_t) apr_os_threadkey_get(void);
APR_DECLARE(apr_status_t) apr_os_threadkey_get(void)
{
return APR_ENOTIMPL;
}
+
#endif