thread_local variables are not (always?) reset on fork(), so we need a way
to set the current_thread to NULL in the child process.
Implement and use ap_thread_current_after_fork() for that.
* include/httpd.h:
Define ap_thread_current_after_fork().
* server/util.c:
Implement ap_thread_current_after_fork().
* server/mpm/event/event.c, server/mpm/prefork/prefork.c,
server/mpm/worker/worker.c:
Use ap_thread_current_after_fork().
* server/mpm/winnt/child.c:
Windows processes are not fork()ed and each child runs the main(), so
ap_thread_current_create() was already called there.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@
1897472 13f79535-47bb-0310-9956-
ffa450edef68
* APR 1.8+ implement those already.
*/
#if APR_HAS_THREAD_LOCAL
-#define AP_HAS_THREAD_LOCAL 1
-#define AP_THREAD_LOCAL APR_THREAD_LOCAL
+#define AP_HAS_THREAD_LOCAL 1
+#define AP_THREAD_LOCAL APR_THREAD_LOCAL
#else
-#define AP_HAS_THREAD_LOCAL 0
+#define AP_HAS_THREAD_LOCAL 0
#endif
-#define ap_thread_create apr_thread_create
-#define ap_thread_current apr_thread_current
-#define ap_thread_current_create apr_thread_current_create
+#define ap_thread_create apr_thread_create
+#define ap_thread_current apr_thread_current
+#define ap_thread_current_create apr_thread_current_create
+#define ap_thread_current_after_fork apr_thread_current_after_fork
#else /* !APR_VERSION_AT_LEAST(1,8,0) */
AP_DECLARE(apr_status_t) ap_thread_current_create(apr_thread_t **current,
apr_threadattr_t *attr,
apr_pool_t *pool);
+AP_DECLARE(void) ap_thread_current_after_fork(void);
AP_DECLARE(apr_thread_t *) ap_thread_current(void);
#endif /* !APR_VERSION_AT_LEAST(1,8,0) */
}
if (!pid) {
+#if AP_HAS_THREAD_LOCAL
+ ap_thread_current_after_fork();
+#endif
+
my_bucket = &retained->buckets[bucket];
#ifdef HAVE_BINDPROCESSOR
}
if (!pid) {
+#if AP_HAS_THREAD_LOCAL
+ ap_thread_current_after_fork();
+#endif
+
my_bucket = &retained->buckets[bucket];
#ifdef HAVE_BINDPROCESSOR
}
-#if AP_HAS_THREAD_LOCAL
-static apr_status_t main_thread_cleanup(void *arg)
-{
- apr_thread_t *thd = arg;
- apr_pool_destroy(apr_thread_pool_get(thd));
- return APR_SUCCESS;
-}
-#endif
-
void child_main(apr_pool_t *pconf, DWORD parent_pid)
{
apr_status_t status;
apr_pool_create(&pchild, pconf);
apr_pool_tag(pchild, "pchild");
-#if AP_HAS_THREAD_LOCAL
- /* Create an apr_thread_t for the main child thread to set up its
- * Thread Local Storage. Since it's detached and it won't
- * apr_thread_exit(), destroy its pool before exiting via
- * a pchild cleanup
- */
- {
- apr_thread_t *main_thd = NULL;
- apr_threadattr_t *main_thd_attr = NULL;
- if (apr_threadattr_create(&main_thd_attr, pchild)
- || apr_threadattr_detach_set(main_thd_attr, 1)
- || ap_thread_current_create(&main_thd, main_thd_attr,
- pchild)) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, 0, ap_server_conf, APLOGNO(10376)
- "Couldn't initialize child main thread");
- exit(APEXIT_CHILDINIT);
- }
- apr_pool_cleanup_register(pchild, main_thd, main_thread_cleanup,
- apr_pool_cleanup_null);
- }
-#endif
-
ap_run_child_init(pchild, ap_server_conf);
listener_shutdown_event = CreateEvent(NULL, TRUE, FALSE, NULL);
}
if (!pid) {
+#if AP_HAS_THREAD_LOCAL
+ ap_thread_current_after_fork();
+#endif
+
my_bucket = &retained->buckets[bucket];
#ifdef HAVE_BINDPROCESSOR
apr_allocator_t *allocator;
apr_pool_t *p;
- *current = NULL;
+ *current = ap_thread_current();
+ if (*current) {
+ return APR_EEXIST;
+ }
rv = apr_allocator_create(&allocator);
if (rv != APR_SUCCESS) {
return APR_SUCCESS;
}
+AP_DECLARE(void) ap_thread_current_after_fork(void)
+{
+#if AP_HAS_THREAD_LOCAL
+ current_thread = NULL;
+#endif
+}
+
AP_DECLARE(apr_thread_t *) ap_thread_current(void)
{
#if AP_HAS_THREAD_LOCAL