diff options
author | Yann Ylavic <ylavic@apache.org> | 2022-01-25 17:34:57 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2022-01-25 17:34:57 +0000 |
commit | 604485905718803811a4b68cd2717a3712500d4a (patch) | |
tree | e4b7c189dacd6e94365d420edb5e59d01f4b965b /include | |
parent | a6f105f7d4451f64b98cff16804a0158ddd29bff (diff) | |
download | httpd-604485905718803811a4b68cd2717a3712500d4a.tar.gz |
core: Efficient ap_thread_current() when apr_thread_local() is missing.
#define ap_thread_create, ap_thread_current_create and ap_thread_current to
their apr-1.8+ equivalent if available, or implement them using the compiler's
thread_local mechanism if available, or finally provide stubs otherwise.
#define AP_HAS_THREAD_LOCAL to 1 in the two former case or 0 otherwise, while
AP_THREAD_LOCAL is defined to the compiler's keyword iff AP_HAS_THREAD_LOCAL.
Replace all apr_thread_create() calls with ap_thread_create() so that httpd
threads can use ap_thread_current()'s pool data as Thread Local Storage.
Bump MMN minor.
* include/httpd.h():
Define AP_HAS_THREAD_LOCAL, AP_THREAD_LOCAL (eventually), ap_thread_create(),
ap_thread_current_create() and ap_thread_current().
* server/util.c:
Implement ap_thread_create(), ap_thread_current_create() and
ap_thread_current() when APR < 1.8.
* modules/core/mod_watchdog.c, modules/http2/h2_workers.c,
modules/ssl/mod_ssl_ct.c:
Use ap_thread_create() instead of apr_thread_create.
* server/main.c:
Use AP_HAS_THREAD_LOCAL and ap_thread_current_create instead of APR's.
* server/util_pcre.c:
Use AP_HAS_THREAD_LOCAL and ap_thread_current instead of APR's.
* server/mpm/event/event.c, server/mpm/worker/worker.c,
server/mpm/prefork/prefork.c:
Use ap_thread_create() instead of apr_thread_create.
Create an apr_thread_t/ap_thread_current() for the main chaild thread usable
at child_init().
* server/mpm/winnt/child.c:
Use ap_thread_create() instead of CreateThread().
Create an apr_thread_t/ap_thread_current() for the main chaild thread usable
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897460 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'include')
-rw-r--r-- | include/ap_mmn.h | 6 | ||||
-rw-r--r-- | include/httpd.h | 50 |
2 files changed, 54 insertions, 2 deletions
diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 25709472db..6e35c4fee1 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -700,7 +700,9 @@ * 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() + * and ap_thread_current() + * */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -708,7 +710,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20211221 #endif -#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 3 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index f9f36fee5b..60e8948b87 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -47,6 +47,7 @@ #include "ap_release.h" #include "apr.h" +#include "apr_version.h" #include "apr_general.h" #include "apr_tables.h" #include "apr_pools.h" @@ -2563,6 +2564,55 @@ AP_DECLARE(void *) ap_realloc(void *ptr, size_t size) AP_FN_ATTR_WARN_UNUSED_RESULT AP_FN_ATTR_ALLOC_SIZE(2); +#if APR_VERSION_AT_LEAST(1,8,0) + +/** + * APR 1.8+ implement those already. + */ +#if APR_HAS_THREAD_LOCAL +#define AP_HAS_THREAD_LOCAL 1 +#define AP_THREAD_LOCAL APR_THREAD_LOCAL +#else +#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 + +#else /* !APR_VERSION_AT_LEAST(1,8,0) */ + +#if APR_HAS_THREADS +/** + * AP_THREAD_LOCAL keyword mapping the compiler's. + */ +#if defined(__cplusplus) && __cplusplus >= 201103L +#define AP_THREAD_LOCAL thread_local +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 +#define AP_THREAD_LOCAL _Thread_local +#elif defined(__GNUC__) /* works for clang too */ +#define AP_THREAD_LOCAL __thread +#elif defined(WIN32) && defined(_MSC_VER) +#define AP_THREAD_LOCAL __declspec(thread) +#endif +#endif /* APR_HAS_THREADS */ + +#ifndef AP_THREAD_LOCAL +#define AP_HAS_THREAD_LOCAL 0 +#define ap_thread_create apr_thread_create +#else /* AP_THREAD_LOCAL */ +#define AP_HAS_THREAD_LOCAL 1 +AP_DECLARE(apr_status_t) ap_thread_create(apr_thread_t **thread, + apr_threadattr_t *attr, + 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(apr_thread_t *) ap_thread_current(void); + +#endif /* !APR_VERSION_AT_LEAST(1,8,0) */ + /** * Get server load params * @param ld struct to populate: -1 in fields means error |