nginx/src/event/ngx_event_spinlock.c

27 lines
383 B
C
Raw Normal View History

2004-06-22 03:22:53 +08:00
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;
}
}
}
}