Mercurial > hg > nginx-vendor-current
annotate src/core/ngx_spinlock.c @ 532:f7ec98e3caeb NGINX_0_8_18
nginx 0.8.18
*) Feature: the "read_ahead" directive.
*) Feature: now several "perl_modules" directive may be used.
*) Feature: the "limit_req_log_level" and "limit_conn_log_level"
directives.
*) Bugfix: now "limit_req" directive conforms to the leaky bucket
algorithm.
Thanks to Maxim Dounin.
*) Bugfix: nginx did not work on Linux/sparc.
Thanks to Marcus Ramberg.
*) Bugfix: nginx sent '\0' in a "Location" response header line on
MKCOL request.
Thanks to Xie Zhenye.
*) Bugfix: zero status code was logged instead of 499 status code; the
bug had appeared in 0.8.11.
*) Bugfix: socket leak; the bug had appeared in 0.8.11.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 06 Oct 2009 00:00:00 +0400 |
parents | 73e8476f9142 |
children | d0f7a625f27c |
rev | line source |
---|---|
0 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
112 | 11 void |
160 | 12 ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin) |
0 | 13 { |
14 | |
15 #if (NGX_HAVE_ATOMIC_OPS) | |
16 | |
160 | 17 ngx_uint_t i, n; |
0 | 18 |
19 for ( ;; ) { | |
20 | |
160 | 21 if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) { |
22 return; | |
23 } | |
24 | |
25 if (ngx_ncpu > 1) { | |
26 | |
27 for (n = 1; n < spin; n <<= 1) { | |
0 | 28 |
160 | 29 for (i = 0; i < n; i++) { |
30 ngx_cpu_pause(); | |
31 } | |
0 | 32 |
160 | 33 if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) { |
34 return; | |
35 } | |
0 | 36 } |
37 } | |
160 | 38 |
39 ngx_sched_yield(); | |
0 | 40 } |
41 | |
42 #else | |
43 | |
44 #if (NGX_THREADS) | |
45 | |
46 #error ngx_spinlock() or ngx_atomic_cmp_set() are not defined ! | |
47 | |
48 #endif | |
49 | |
50 #endif | |
51 | |
52 } |