summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2022-01-25 20:14:55 +0000
committerYann Ylavic <ylavic@apache.org>2022-01-25 20:14:55 +0000
commit865e0f3805b4f46d77a43bc661fd793dbaaa7ff6 (patch)
tree33c018b578c888228c8b6ed79741c439a25370ed
parent05023098b8283a21bf1c5229db6c6c73c6407a0e (diff)
downloadapr-865e0f3805b4f46d77a43bc661fd793dbaaa7ff6.tar.gz
apr_thread: Follow up to r1897207: Provide apr_thread_current_after_fork().
thread_local variables are not (always?) reset on fork(), so APR (and the user) needs a way to set the current_thread to NULL. Use apr_thread_current_after_fork() in apr_proc_fork()'s child process. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1897470 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/apr_thread_proc.h8
-rw-r--r--threadproc/beos/proc.c3
-rw-r--r--threadproc/beos/thread.c7
-rw-r--r--threadproc/netware/proc.c3
-rw-r--r--threadproc/netware/thread.c7
-rw-r--r--threadproc/os2/proc.c3
-rw-r--r--threadproc/os2/thread.c7
-rw-r--r--threadproc/unix/proc.c3
-rw-r--r--threadproc/unix/thread.c7
-rw-r--r--threadproc/win32/thread.c7
10 files changed, 54 insertions, 1 deletions
diff --git a/include/apr_thread_proc.h b/include/apr_thread_proc.h
index 270cb24b2..85f697dd2 100644
--- a/include/apr_thread_proc.h
+++ b/include/apr_thread_proc.h
@@ -289,7 +289,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
void *data, apr_pool_t *cont);
/**
- * Setup the current os_thread as an apr_thread
+ * Setup the current native thread as an apr_thread
* @param current The current apr_thread set up (or reused)
* @param attr The threadattr associated with the current thread
* @param pool The parent pool of the current thread
@@ -299,6 +299,12 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
APR_DECLARE(apr_status_t) apr_thread_current_create(apr_thread_t **current,
apr_threadattr_t *attr,
apr_pool_t *pool);
+
+/**
+ * Clear the current thread after fork()
+ */
+APR_DECLARE(void) apr_thread_current_after_fork(void);
+
/**
* Get the current thread
* @param The current apr_thread, NULL if it is not an apr_thread or if
diff --git a/threadproc/beos/proc.c b/threadproc/beos/proc.c
index e3698082f..cd6f9a250 100644
--- a/threadproc/beos/proc.c
+++ b/threadproc/beos/proc.c
@@ -170,6 +170,9 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
}
}
+#if AP_HAS_THREAD_LOCAL
+ apr_thread_current_after_fork();
+#endif
proc->pid = pid;
proc->in = NULL;
proc->out = NULL;
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c
index 25bd0d2bb..435c2c8a9 100644
--- a/threadproc/beos/thread.c
+++ b/threadproc/beos/thread.c
@@ -184,6 +184,13 @@ APR_DECLARE(apr_status_t) apr_thread_current_create(apr_thread_t **current,
return APR_SUCCESS;
}
+APR_DECLARE(void) apr_thread_current_after_fork(void)
+{
+#if APR_HAS_THREAD_LOCAL
+ current_thread = NULL;
+#endif
+}
+
APR_DECLARE(apr_thread_t *) apr_thread_current(void)
{
#if APR_HAS_THREAD_LOCAL
diff --git a/threadproc/netware/proc.c b/threadproc/netware/proc.c
index f5d24b21b..1a6de7b7b 100644
--- a/threadproc/netware/proc.c
+++ b/threadproc/netware/proc.c
@@ -226,6 +226,9 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
return errno;
}
else if (pid == 0) {
+#if AP_HAS_THREAD_LOCAL
+ apr_thread_current_after_fork();
+#endif
proc->pid = pid;
proc->in = NULL;
proc->out = NULL;
diff --git a/threadproc/netware/thread.c b/threadproc/netware/thread.c
index 40b6d7259..b45569e3f 100644
--- a/threadproc/netware/thread.c
+++ b/threadproc/netware/thread.c
@@ -219,6 +219,13 @@ APR_DECLARE(apr_status_t) apr_thread_current_create(apr_thread_t **current,
return APR_SUCCESS;
}
+APR_DECLARE(void) apr_thread_current_after_fork(void)
+{
+#if APR_HAS_THREAD_LOCAL
+ current_thread = NULL;
+#endif
+}
+
APR_DECLARE(apr_thread_t *) apr_thread_current(void)
{
#if APR_HAS_THREAD_LOCAL
diff --git a/threadproc/os2/proc.c b/threadproc/os2/proc.c
index cd7500129..beb100908 100644
--- a/threadproc/os2/proc.c
+++ b/threadproc/os2/proc.c
@@ -227,6 +227,9 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
return errno;
}
else if (pid == 0) {
+#if AP_HAS_THREAD_LOCAL
+ apr_thread_current_after_fork();
+#endif
proc->pid = pid;
proc->in = NULL;
proc->out = NULL;
diff --git a/threadproc/os2/thread.c b/threadproc/os2/thread.c
index d23be9aed..fc3015088 100644
--- a/threadproc/os2/thread.c
+++ b/threadproc/os2/thread.c
@@ -187,6 +187,13 @@ APR_DECLARE(apr_status_t) apr_thread_current_create(apr_thread_t **current,
return APR_SUCCESS;
}
+APR_DECLARE(void) apr_thread_current_after_fork(void)
+{
+#if APR_HAS_THREAD_LOCAL
+ current_thread = NULL;
+#endif
+}
+
APR_DECLARE(apr_thread_t *) apr_thread_current(void)
{
#if APR_HAS_THREAD_LOCAL
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c
index ed7a05fda..ad31c814f 100644
--- a/threadproc/unix/proc.c
+++ b/threadproc/unix/proc.c
@@ -234,6 +234,9 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
return errno;
}
else if (pid == 0) {
+#if AP_HAS_THREAD_LOCAL
+ apr_thread_current_after_fork();
+#endif
proc->pid = getpid();
/* Do the work needed for children PRNG(s). */
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index d3eac6509..78b803727 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -260,6 +260,13 @@ APR_DECLARE(apr_status_t) apr_thread_current_create(apr_thread_t **current,
return APR_SUCCESS;
}
+APR_DECLARE(void) apr_thread_current_after_fork(void)
+{
+#if APR_HAS_THREAD_LOCAL
+ current_thread = NULL;
+#endif
+}
+
APR_DECLARE(apr_thread_t *) apr_thread_current(void)
{
#if APR_HAS_THREAD_LOCAL
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index c4fd81fff..68251f881 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -199,6 +199,13 @@ APR_DECLARE(apr_status_t) apr_thread_current_create(apr_thread_t **current,
return APR_SUCCESS;
}
+APR_DECLARE(void) apr_thread_current_after_fork(void)
+{
+#if APR_HAS_THREAD_LOCAL
+ current_thread = NULL;
+#endif
+}
+
APR_DECLARE(apr_thread_t *) apr_thread_current(void)
{
#if APR_HAS_THREAD_LOCAL