Mercurial > hg > nginx-vendor-0-6
comparison src/core/ngx_spinlock.c @ 160:73e8476f9142 NGINX_0_3_27
nginx 0.3.27
*) Change: the "variables_hash_max_size" and
"variables_hash_bucket_size" directives.
*) Feature: the $body_bytes_sent variable can be used not only in the
"log_format" directive.
*) Feature: the $ssl_protocol and $ssl_cipher variables.
*) Feature: the cache line size detection for widespread CPUs at start
time.
*) Feature: now the "accept_mutex" directive is supported using
fcntl(2) on platforms different from i386, amd64, sparc64, and ppc.
*) Feature: the "lock_file" directive and the --with-lock-path=PATH
autoconfiguration directive.
*) Bugfix: if the HTTPS protocol was used in the "proxy_pass" directive
then the requests with the body was not transferred.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 08 Feb 2006 00:00:00 +0300 |
parents | 408f195b3482 |
children |
comparison
equal
deleted
inserted
replaced
159:25c27e983933 | 160:73e8476f9142 |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 | 9 |
10 | 10 |
11 /* | |
12 * TODO: the P4 optimized assembler version with the "pause" operation | |
13 */ | |
14 | |
15 void | 11 void |
16 ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin) | 12 ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin) |
17 { | 13 { |
18 | 14 |
19 #if (NGX_HAVE_ATOMIC_OPS) | 15 #if (NGX_HAVE_ATOMIC_OPS) |
20 | 16 |
21 ngx_uint_t tries; | 17 ngx_uint_t i, n; |
22 | |
23 tries = 0; | |
24 | 18 |
25 for ( ;; ) { | 19 for ( ;; ) { |
26 | 20 |
27 if (*lock) { | 21 if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) { |
28 if (ngx_ncpu > 1 && tries++ < spin) { | 22 return; |
29 continue; | 23 } |
30 } | |
31 | 24 |
32 ngx_sched_yield(); | 25 if (ngx_ncpu > 1) { |
33 | 26 |
34 tries = 0; | 27 for (n = 1; n < spin; n <<= 1) { |
35 | 28 |
36 } else { | 29 for (i = 0; i < n; i++) { |
37 if (ngx_atomic_cmp_set(lock, 0, 1)) { | 30 ngx_cpu_pause(); |
38 return; | 31 } |
32 | |
33 if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) { | |
34 return; | |
35 } | |
39 } | 36 } |
40 } | 37 } |
38 | |
39 ngx_sched_yield(); | |
41 } | 40 } |
42 | 41 |
43 #else | 42 #else |
44 | 43 |
45 #if (NGX_THREADS) | 44 #if (NGX_THREADS) |