Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-06-30 19:30:41 +0400
committerIgor Sysoev <igor@sysoev.ru>2004-06-30 19:30:41 +0400
commit078d1b2c2263690f2f6b7217b567eeeb525910d0 (patch)
treedfb82cccd10c3dee8a500506f7692b0445200e5c /src/core/ngx_spinlock.c
parent0a94cfd2ae9ca87b4d988b5066f739a3034f3bff (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.c29
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;
+ }
+ }
+ }
+}