aboutsummaryrefslogtreecommitdiff
path: root/kernel/include/proc/spinlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/include/proc/spinlock.h')
-rw-r--r--kernel/include/proc/spinlock.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/kernel/include/proc/spinlock.h b/kernel/include/proc/spinlock.h
new file mode 100644
index 0000000..4ce57c8
--- /dev/null
+++ b/kernel/include/proc/spinlock.h
@@ -0,0 +1,37 @@
+#pragma once
+
+typedef struct spinlock
+{
+ volatile char s_locked;
+} spinlock_t;
+
+#define SPINLOCK_INITIALIZER(lock) \
+ { \
+ .s_locked = 0 \
+ }
+
+/**
+ * Initializes the fields of the specified spinlock_t
+ * @param lock the spinlock to initialize
+ */
+void spinlock_init(spinlock_t *lock);
+
+/**
+ * Locks the specified spinlock.
+ *
+ * Note: this function may spin on the current core.
+ *
+ * Note: these locks are not re-entrant
+ *
+ * @param lock the spinlock to lock
+ */
+void spinlock_lock(spinlock_t *lock);
+
+/**
+ * Unlocks the specified spinlock.
+ *
+ * @param lock the spinlock to unlock
+ */
+void spinlock_unlock(spinlock_t *lock);
+
+long spinlock_ownslock(spinlock_t *lock);