diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ngx_cycle.c | 4 | ||||
-rw-r--r-- | src/core/ngx_cycle.h | 8 | ||||
-rw-r--r-- | src/core/ngx_regex.c | 50 |
3 files changed, 56 insertions, 6 deletions
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index 5a19f302f..fe6abc25f 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -15,6 +15,10 @@ static ngx_event_t ngx_cleaner_event; ngx_uint_t ngx_test_config; +#if (NGX_THREADS) +ngx_tls_key_t ngx_core_tls_key; +#endif + /* STUB NAME */ static ngx_connection_t dumb; diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index 5708ce406..84521898c 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -49,6 +49,11 @@ typedef struct { } ngx_core_conf_t; +typedef struct { + ngx_pool_t *pool; /* pcre's malloc() pool */ +} ngx_core_tls_t; + + ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle); ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle); void ngx_delete_pidfile(ngx_cycle_t *cycle); @@ -60,6 +65,9 @@ extern volatile ngx_cycle_t *ngx_cycle; extern ngx_array_t ngx_old_cycles; extern ngx_module_t ngx_core_module; extern ngx_uint_t ngx_test_config; +#if (NGX_THREADS) +extern ngx_tls_key_t ngx_core_tls_key; +#endif #endif /* _NGX_CYCLE_H_INCLUDED_ */ diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c index 617fddcbb..f4d827d83 100644 --- a/src/core/ngx_regex.c +++ b/src/core/ngx_regex.c @@ -7,7 +7,6 @@ static void *ngx_regex_malloc(size_t size); static void ngx_regex_free(void *p); -/* THREADS: this pool should be private for each thread */ static ngx_pool_t *ngx_pcre_pool; @@ -21,12 +20,29 @@ void ngx_regex_init() ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options, ngx_pool_t *pool, ngx_str_t *err) { - int erroff; - const char *errstr; - ngx_regex_t *re; + int erroff; + const char *errstr; + ngx_regex_t *re; +#if (NGX_THREADS) + ngx_core_tls_t *tls; + +#if (NGX_SUPPRESS_WARN) + tls = NULL; +#endif + + if (ngx_threaded) { + tls = ngx_thread_get_tls(ngx_core_tls_key); + tls->pool = pool; + } else { + ngx_pcre_pool = pool; + } + +#else ngx_pcre_pool = pool; +#endif + re = pcre_compile((const char *) pattern->data, (int) options, &errstr, &erroff, NULL); @@ -44,7 +60,15 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options, /* ensure that there is no current pool */ +#if (NGX_THREADS) + if (ngx_threaded) { + tls->pool = NULL; + } else { + ngx_pcre_pool = NULL; + } +#else ngx_pcre_pool = NULL; +#endif return re; } @@ -68,8 +92,22 @@ ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, static void *ngx_regex_malloc(size_t size) { - if (ngx_pcre_pool) { - return ngx_palloc(ngx_pcre_pool, size); + ngx_pool_t *pool; +#if (NGX_THREADS) + ngx_core_tls_t *tls; + + if (ngx_threaded) { + tls = ngx_thread_get_tls(ngx_core_tls_key); + pool = tls->pool; + } else { + pool = ngx_pcre_pool; + } +#else + pool = ngx_pcre_pool; +#endif + + if (pool) { + return ngx_palloc(pool, size); } return NULL; |