nginx-0.0.7-2004-06-30-19:30:41 import
diff --git a/src/core/ngx_spinlock.c b/src/core/ngx_spinlock.c new file mode 100644 index 0000000..c3c65d3 --- /dev/null +++ b/src/core/ngx_spinlock.c
@@ -0,0 +1,29 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +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; + } + } + } +}