mirror of
https://github.com/nginx/nginx.git
synced 2024-12-16 14:19:00 +08:00
27 lines
383 B
C
27 lines
383 B
C
|
|
||
|
|
||
|
void _spinlock(ngx_atomic_t *lock)
|
||
|
{
|
||
|
ngx_int_t tries;
|
||
|
|
||
|
tries = 0;
|
||
|
|
||
|
for ( ;; ) {
|
||
|
|
||
|
if (*lock) {
|
||
|
if (ngx_ncpu > 1 && tries++ < 1000) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
sched_yield();
|
||
|
tries = 0;
|
||
|
|
||
|
} else {
|
||
|
if (ngx_atomic_cmp_set(lock, 0, 1)) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|