Mercurial > hg > nginx
comparison src/core/ngx_spinlock.c @ 373:018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 30 Jun 2004 15:30:41 +0000 |
parents | src/event/ngx_event_spinlock.c@f2755a2885c8 |
children | 5cdc4838d4e8 |
comparison
equal
deleted
inserted
replaced
372:c9fdfccebc49 | 373:018569a8f09c |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_core.h> | |
4 | |
5 | |
6 void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin) | |
7 { | |
8 ngx_uint_t tries; | |
9 | |
10 tries = 0; | |
11 | |
12 for ( ;; ) { | |
13 | |
14 if (*lock) { | |
15 if (ngx_ncpu > 1 && tries++ < spin) { | |
16 continue; | |
17 } | |
18 | |
19 ngx_sched_yield(); | |
20 | |
21 tries = 0; | |
22 | |
23 } else { | |
24 if (ngx_atomic_cmp_set(lock, 0, 1)) { | |
25 return; | |
26 } | |
27 } | |
28 } | |
29 } |