summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_spinlock.h
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-01-17 20:00:00 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-01-17 20:00:00 +0300
commit16cbf3c076a0aca6d47adaf3f719493674cf2363 (patch)
treee6530480020f62a2bdbf249988ec3e2a751d3927 /src/nxt_spinlock.h
downloadunit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.gz
unit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.bz2
Initial version.
Diffstat (limited to 'src/nxt_spinlock.h')
-rw-r--r--src/nxt_spinlock.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/nxt_spinlock.h b/src/nxt_spinlock.h
new file mode 100644
index 00000000..bdc3a5f6
--- /dev/null
+++ b/src/nxt_spinlock.h
@@ -0,0 +1,57 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NXT_UNIX_SPINLOCK_H_INCLUDED_
+#define _NXT_UNIX_SPINLOCK_H_INCLUDED_
+
+
+#if (NXT_THREADS)
+
+#if (NXT_HAVE_MACOSX_SPINLOCK)
+
+#include <libkern/OSAtomic.h>
+
+typedef OSSpinLock nxt_thread_spinlock_t;
+
+#define \
+nxt_thread_spin_init(ncpu, count)
+
+#else
+
+typedef nxt_atomic_t nxt_thread_spinlock_t;
+
+NXT_EXPORT void nxt_thread_spin_init(nxt_uint_t ncpu, nxt_uint_t count);
+
+#endif
+
+
+NXT_EXPORT void nxt_thread_spin_lock(nxt_thread_spinlock_t *lock);
+NXT_EXPORT nxt_bool_t nxt_thread_spin_trylock(nxt_thread_spinlock_t *lock);
+NXT_EXPORT void nxt_thread_spin_unlock(nxt_thread_spinlock_t *lock);
+
+
+#else /* !(NXT_THREADS) */
+
+
+typedef nxt_atomic_t nxt_thread_spinlock_t;
+
+#define \
+nxt_thread_spin_init(ncpu, count)
+
+#define \
+nxt_thread_spin_lock(lock)
+
+#define \
+nxt_thread_spin_trylock(lock) \
+ 1
+
+#define \
+nxt_thread_spin_unlock(lock)
+
+#endif
+
+
+#endif /* _NXT_UNIX_SPINLOCK_H_INCLUDED_ */