From 3a58935936f3baca6bbccafc375c8f5656c5d39a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Fri, 21 Aug 2009 09:06:35 +0000 Subject: *) share temporary number between workers *) randomize collision offset --- src/core/ngx_file.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/core/ngx_file.c') diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c index 3a489608a..45bb4ca4f 100644 --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -8,8 +8,9 @@ #include -static ngx_atomic_uint_t ngx_temp_number; -static ngx_atomic_uint_t ngx_random_number; +static ngx_atomic_t temp_number = 0; +ngx_atomic_t *ngx_temp_number = &temp_number; +ngx_atomic_int_t ngx_random_number = 123456; ssize_t @@ -205,22 +206,16 @@ ngx_create_full_path(u_char *dir, ngx_uint_t access) } -void -ngx_init_temp_number(void) -{ - ngx_temp_number = 0; - ngx_random_number = 123456; -} - - ngx_atomic_uint_t ngx_next_temp_number(ngx_uint_t collision) { - if (collision) { - ngx_temp_number += ngx_random_number; - } + ngx_atomic_uint_t n, add; + + add = collision ? ngx_random_number : 1; + + n = ngx_atomic_fetch_add(ngx_temp_number, add); - return ngx_temp_number++; + return n + add; } -- cgit