Mercurial > hg > nginx
comparison src/event/ngx_event_spinlock.c @ 363:f2755a2885c8
nginx-0.0.7-2004-06-21-23:22:53 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 21 Jun 2004 19:22:53 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
362:7650aea1816f | 363:f2755a2885c8 |
---|---|
1 | |
2 | |
3 void _spinlock(ngx_atomic_t *lock) | |
4 { | |
5 ngx_int_t tries; | |
6 | |
7 tries = 0; | |
8 | |
9 for ( ;; ) { | |
10 | |
11 if (*lock) { | |
12 if (ngx_ncpu > 1 && tries++ < 1000) { | |
13 continue; | |
14 } | |
15 | |
16 sched_yield(); | |
17 tries = 0; | |
18 | |
19 } else { | |
20 if (ngx_atomic_cmp_set(lock, 0, 1)) { | |
21 return; | |
22 } | |
23 } | |
24 } | |
25 } | |
26 |