* add PROXY_WORKER_UDS_PATH_SIZE.
* 20211221.1 (2.5.1-dev) Add read_line to scoreboard.
* 20211221.2 (2.5.1-dev) Add AGAIN, AP_MPMQ_CAN_AGAIN.
- * 20211221.3 (2.5.1-dev) Add ap_thread_create(), ap_thread_current_create()
+ * 20211221.3 (2.5.1-dev) Add ap_thread_create(), ap_thread_main_create()
* and ap_thread_current()
*
*/
#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_current_after_fork apr_thread_current_after_fork
#else /* !APR_VERSION_AT_LEAST(1,8,0) */
apr_thread_start_t func,
void *data, apr_pool_t *pool);
#endif /* AP_THREAD_LOCAL */
-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) */
+AP_DECLARE(apr_status_t) ap_thread_main_create(apr_thread_t **thread,
+ apr_pool_t *pool);
+
#else /* !APR_HAS_THREADS */
#define AP_HAS_THREAD_LOCAL 0
apr_pool_pre_cleanup_register(process->pconf, NULL, deregister_all_hooks);
}
-#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
-
static process_rec *init_process(int *argc, const char * const * *argv)
{
process_rec *process;
process->short_name = apr_filepath_name_get((*argv)[0]);
#if AP_HAS_THREAD_LOCAL
- /* Create an apr_thread_t for the main 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 process->pool cleanup
- */
{
- apr_thread_t *main_thd = NULL;
- apr_threadattr_t *main_thd_attr = NULL;
- if (apr_threadattr_create(&main_thd_attr, process->pool)
- || apr_threadattr_detach_set(main_thd_attr, 1)
- || ap_thread_current_create(&main_thd, main_thd_attr,
- process->pool)) {
+ apr_status_t rv;
+ apr_thread_t *thd = NULL;
+ if ((rv = ap_thread_main_create(&thd, process->pool))) {
char ctimebuff[APR_CTIME_LEN];
apr_ctime(ctimebuff, apr_time_now());
fprintf(stderr, "[%s] [crit] (%d) %s: %s failed "
- "to initialize thread context, exiting\n",
- ctimebuff, stat, (*argv)[0], failed);
+ "to initialize thread context (%i), exiting\n",
+ ctimebuff, stat, (*argv)[0], failed, rv);
apr_terminate();
exit(1);
}
- apr_pool_cleanup_register(process->pool, main_thd, main_thread_cleanup,
- apr_pool_cleanup_null);
}
#endif
}
}
-#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
-
static void child_main(int child_num_arg, int child_bucket)
{
apr_thread_t **threads;
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
- */
if (!one_process) {
- 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(10377)
+ apr_thread_t *thd = NULL;
+ if ((rv = ap_thread_main_create(&thd, pchild))) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, APLOGNO(10377)
"Couldn't initialize child main thread");
clean_child_exit(APEXIT_CHILDFATAL);
}
- apr_pool_cleanup_register(pchild, main_thd, main_thread_cleanup,
- apr_pool_cleanup_null);
}
#endif
}
#endif
-#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
-
static void child_main(int child_num_arg, int child_bucket)
{
#if APR_HAS_THREADS
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
- */
if (one_process) {
thd = ap_thread_current();
}
- else {
- 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(&thd, main_thd_attr,
- pchild)) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, 0, ap_server_conf, APLOGNO(10378)
- "Couldn't initialize child main thread");
- clean_child_exit(APEXIT_CHILDFATAL);
- }
- apr_pool_cleanup_register(pchild, thd, main_thread_cleanup,
- apr_pool_cleanup_null);
+ else if ((status = ap_thread_main_create(&thd, pchild))) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf, APLOGNO(10378)
+ "Couldn't initialize child main thread");
+ clean_child_exit(APEXIT_CHILDFATAL);
}
#elif APR_HAS_THREADS
{
}
}
-#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
-
static void child_main(int child_num_arg, int child_bucket)
{
apr_thread_t **threads;
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
- */
if (!one_process) {
- 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(10375)
+ apr_thread_t *thd = NULL;
+ if ((rv = ap_thread_main_create(&thd, pchild))) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, APLOGNO(10375)
"Couldn't initialize child main thread");
clean_child_exit(APEXIT_CHILDFATAL);
}
- apr_pool_cleanup_register(pchild, main_thd, main_thread_cleanup,
- apr_pool_cleanup_null);
}
#endif
return p;
}
-#if APR_HAS_THREADS && !APR_VERSION_AT_LEAST(1,8,0)
+#if APR_HAS_THREADS
+
+#if APR_VERSION_AT_LEAST(1,8,0)
+
+#define ap_thread_current_create apr_thread_current_create
+
+#else /* !APR_VERSION_AT_LEAST(1,8,0) */
#if AP_HAS_THREAD_LOCAL
+
struct thread_ctx {
apr_thread_start_t func;
void *data;
ctx->data = data;
return apr_thread_create(thread, attr, thread_start, ctx, pool);
}
+
#endif /* AP_HAS_THREAD_LOCAL */
-AP_DECLARE(apr_status_t) ap_thread_current_create(apr_thread_t **current,
- apr_threadattr_t *attr,
- apr_pool_t *pool)
+static apr_status_t ap_thread_current_create(apr_thread_t **current,
+ apr_threadattr_t *attr,
+ apr_pool_t *pool)
{
apr_status_t rv;
- apr_os_thread_t osthd;
apr_abortfunc_t abort_fn = apr_pool_abort_get(pool);
apr_allocator_t *allocator;
+ apr_os_thread_t osthd;
apr_pool_t *p;
*current = ap_thread_current();
#endif /* !APR_VERSION_AT_LEAST(1,8,0) */
+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;
+}
+
+AP_DECLARE(apr_status_t) ap_thread_main_create(apr_thread_t **thread,
+ apr_pool_t *pool)
+{
+ apr_status_t rv;
+ apr_threadattr_t *attr = NULL;
+
+ /* Create an apr_thread_t for the main child thread to set up its Thread
+ * Local Storage. Since it's detached and won't apr_thread_exit(), destroy
+ * its pool before exiting via a cleanup of the given pool.
+ */
+ if ((rv = apr_threadattr_create(&attr, pool))
+ || (rv = apr_threadattr_detach_set(attr, 1))
+ || (rv = ap_thread_current_create(thread, attr, pool))) {
+ *thread = NULL;
+ return rv;
+ }
+
+ apr_pool_cleanup_register(pool, *thread, main_thread_cleanup,
+ apr_pool_cleanup_null);
+ return APR_SUCCESS;
+}
+
+#endif /* APR_HAS_THREADS */
+
AP_DECLARE(void) ap_get_sload(ap_sload_t *ld)
{
int i, j, server_limit, thread_limit;