Mercurial > hg > nginx-vendor-current
annotate src/core/ngx_spinlock.c @ 116:e38f51cd0905 NGINX_0_3_5
nginx 0.3.5
*) Bugfix: the segmentation fault may occurred if the IMAP/POP3 login
was changed by authorization server; bug appeared in 0.2.2.
*) Bugfix: the accept mutex did not work and all connections were
handled by one process; bug appeared in 0.3.3.
*) Bugfix: the timeout did not work if the "rtsig" method and the
"timer_resolution" directive were used.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 21 Oct 2005 00:00:00 +0400 |
parents | 408f195b3482 |
children | 73e8476f9142 |
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 | |
42 | 11 /* |
12 * TODO: the P4 optimized assembler version with the "pause" operation | |
13 */ | |
14 | |
112 | 15 void |
16 ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin) | |
0 | 17 { |
18 | |
19 #if (NGX_HAVE_ATOMIC_OPS) | |
20 | |
21 ngx_uint_t tries; | |
22 | |
23 tries = 0; | |
24 | |
25 for ( ;; ) { | |
26 | |
27 if (*lock) { | |
28 if (ngx_ncpu > 1 && tries++ < spin) { | |
29 continue; | |
30 } | |
31 | |
32 ngx_sched_yield(); | |
33 | |
34 tries = 0; | |
35 | |
36 } else { | |
37 if (ngx_atomic_cmp_set(lock, 0, 1)) { | |
38 return; | |
39 } | |
40 } | |
41 } | |
42 | |
43 #else | |
44 | |
45 #if (NGX_THREADS) | |
46 | |
47 #error ngx_spinlock() or ngx_atomic_cmp_set() are not defined ! | |
48 | |
49 #endif | |
50 | |
51 #endif | |
52 | |
53 } |