summaryrefslogtreecommitdiff
path: root/accel-pppd/triton/spinlock.h
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2011-01-05 15:18:59 +0300
committerDmitry Kozlov <xeb@mail.ru>2011-01-05 15:18:59 +0300
commitf28cb1b0a926f1ea98700b7871537ad1793511fd (patch)
treebaf35570bc6b38b6fab5b6524e8f19f58f71e57f /accel-pppd/triton/spinlock.h
parent2fdf3586c13a72c36f9530084962e29d57dc0329 (diff)
downloadaccel-ppp-f28cb1b0a926f1ea98700b7871537ad1793511fd.tar.gz
accel-ppp-f28cb1b0a926f1ea98700b7871537ad1793511fd.zip
rename accel-pptp to accel-ppp
Diffstat (limited to 'accel-pppd/triton/spinlock.h')
-rw-r--r--accel-pppd/triton/spinlock.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/accel-pppd/triton/spinlock.h b/accel-pppd/triton/spinlock.h
new file mode 100644
index 00000000..bb8dcf44
--- /dev/null
+++ b/accel-pppd/triton/spinlock.h
@@ -0,0 +1,42 @@
+#ifndef __TRITON_SPINLOCK_H
+#define __TRITON_SPINLOCK_H
+
+#if defined(FUTEX_SPINLOCK)
+
+/*#include <unistd.h>
+#include <sys/syscall.h>
+#include <linux/futex.h>
+typedef volatile int __attribute__((aligned)) spinlock_t;
+static inline void _spin_lock(spinlock_t *l)
+{
+ syscall(SYS_futex, l, FUTEX_WAIT, r, NULL, NULL, 0);
+}
+static inline void _spin_unlock(spinlock_t *l)
+{
+ syscall(SYS_futex, l, FUTEX_WAKE, 2, NULL, NULL, 0);
+}
+#define spin_lock(l) _spin_lock(l)
+#define spin_unlock(l) _spin_unlock(l)
+#define SPINLOCK_INITIALIZER 1
+#define spinlock_init(l) {*(l)=1;}*/
+
+#elif defined(GCC_SPINLOCK)
+
+typedef volatile int __attribute__((aligned)) spinlock_t;
+#define spin_lock(l) {while(__sync_lock_test_and_set(l,1));}
+#define spin_unlock(l) __sync_lock_release(l)
+#define SPINLOCK_INITIALIZER 0
+#define spinlock_init(l) {*(l)=0;}
+
+#else
+
+#include <pthread.h>
+typedef pthread_mutex_t spinlock_t;
+#define spin_lock(l) pthread_mutex_lock(l)
+#define spin_unlock(l) pthread_mutex_unlock(l)
+#define SPINLOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define spinlock_init(l) pthread_mutex_init(l,NULL)
+#endif
+
+#endif
+