summaryrefslogtreecommitdiffstats
path: root/sys/lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/lock.c')
-rw-r--r--sys/lock.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/sys/lock.c b/sys/lock.c
new file mode 100644
index 0000000..095a08e
--- /dev/null
+++ b/sys/lock.c
@@ -0,0 +1,25 @@
+#include "lock.h"
+
+extern int _kernel_panic_unlock;
+
+void
+take_mutex(atomic_flag *lock)
+{
+ if(_kernel_panic_unlock) return;
+ while(atomic_flag_test_and_set(lock)) {
+ __builtin_ia32_pause();
+ }
+}
+
+int
+try_take_mutex(atomic_flag *lock)
+{
+ if(_kernel_panic_unlock) return 0;
+ return atomic_flag_test_and_set(lock);
+}
+
+void
+release_mutex(atomic_flag *lock)
+{
+ atomic_flag_clear(lock);
+}