diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-30 19:30:41 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-30 19:30:41 +0400 |
commit | 078d1b2c2263690f2f6b7217b567eeeb525910d0 (patch) | |
tree | dfb82cccd10c3dee8a500506f7692b0445200e5c /src/core/ngx_spinlock.c | |
parent | 0a94cfd2ae9ca87b4d988b5066f739a3034f3bff (diff) |
nginx-0.0.7-2004-06-30-19:30:41 import
Diffstat (limited to 'src/core/ngx_spinlock.c')
-rw-r--r-- | src/core/ngx_spinlock.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <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; + } + } + } +} |