summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2024-03-19 13:03:52 -0400
committerJon Santmyer <jon@jonsantmyer.com>2024-03-19 13:03:52 -0400
commitf004c1ade8d617a82cea2fe249434cccb47a2358 (patch)
tree34571e76039cf2ee2fee93c3f1bdb1bc6d2de5f6 /lib
parentdd5d9e1d48396cbc226ff14fe557a55613c91fcb (diff)
downloadjove-kernel-f004c1ade8d617a82cea2fe249434cccb47a2358.tar.gz
jove-kernel-f004c1ade8d617a82cea2fe249434cccb47a2358.tar.bz2
jove-kernel-f004c1ade8d617a82cea2fe249434cccb47a2358.zip
rename abi to sys. better memory allocation
Diffstat (limited to 'lib')
-rw-r--r--lib/spinlock.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/spinlock.h b/lib/spinlock.h
new file mode 100644
index 0000000..75af28a
--- /dev/null
+++ b/lib/spinlock.h
@@ -0,0 +1,27 @@
+#ifndef JOVE_LIB_SPINLOCK_H
+#define JOVE_LIB_SPINLOCK_H 1
+
+#include <stdatomic.h>
+
+typedef struct Spinlock
+{
+ atomic_flag flg;
+
+ const char *locker_file;
+ const char *locker_func;
+ int locker_line;
+} spinlock_t;
+
+#define spinlock_acquire(lock) \
+ while(atomic_flag_test_and_set_explicit(&lock.flg, memory_order_acquire)) \
+ __builtin_ia32_pause(); \
+ lock.locker_file = __FILE__; \
+ lock.locker_func = __FUNCTION__; \
+ lock.locker_line = __LINE__
+
+#define spinlock_release(lock) \
+ atomic_flag_clear_explicit(&lock.flg, memory_order_release); \
+ lock.locker_file = lock.locker_func = NULL; \
+ lock.locker_line = -1
+
+#endif