diff options
Diffstat (limited to 'src/core/ngx_regex.c')
-rw-r--r-- | src/core/ngx_regex.c | 50 |
1 files changed, 44 insertions, 6 deletions
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; |