diff src/event/ngx_event_spinlock.c @ 363:f2755a2885c8

nginx-0.0.7-2004-06-21-23:22:53 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 21 Jun 2004 19:22:53 +0000
parents
children
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/event/ngx_event_spinlock.c
@@ -0,0 +1,26 @@
+
+
+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;
+            }
+        }
+    }
+}
+