From 078d1b2c2263690f2f6b7217b567eeeb525910d0 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 30 Jun 2004 15:30:41 +0000 Subject: nginx-0.0.7-2004-06-30-19:30:41 import --- src/core/ngx_spinlock.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/core/ngx_spinlock.c (limited to 'src/core/ngx_spinlock.c') diff --git a/src/core/ngx_spinlock.c b/src/core/ngx_spinlock.c new file mode 100644 index 000000000..c3c65d303 --- /dev/null +++ b/src/core/ngx_spinlock.c @@ -0,0 +1,29 @@ + +#include +#include + + +void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin) +{ + ngx_uint_t tries; + + tries = 0; + + for ( ;; ) { + + if (*lock) { + if (ngx_ncpu > 1 && tries++ < spin) { + continue; + } + + ngx_sched_yield(); + + tries = 0; + + } else { + if (ngx_atomic_cmp_set(lock, 0, 1)) { + return; + } + } + } +} -- cgit