]> git.corax.cc Git - corax/commitdiff
Add spinlock implementation to klibc
authorMatthias Kruk <m@m10k.eu>
Thu, 21 Nov 2019 07:22:16 +0000 (16:22 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 21 Nov 2019 07:22:16 +0000 (16:22 +0900)
kernel/include/spinlock.h [new file with mode: 0644]

diff --git a/kernel/include/spinlock.h b/kernel/include/spinlock.h
new file mode 100644 (file)
index 0000000..4ee76f4
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef __SPINLOCK_H
+#define __SPINLOCK_H
+
+#include <corax/types.h>
+
+/* NOTE: The amd64 implementation in spinlock.S needs this to be an u32_t */
+typedef u32_t spinlock_t;
+
+/*
+ * spinlock_lock() - Lock a spinlock, waiting indefinitely
+ *
+ * SYNOPSIS
+ *  void spinlock_lock(spinlock_t *lock);
+ *
+ * DESCRIPTION
+ *  The spinlock_lock() function will indefinitely attempt to lock
+ *  the spinlock pointed to by `lock' until it succeeds, waiting in
+ *  a busy loop.
+ *
+ * RETURN VALUE
+ *  None
+ */
+void spinlock_lock(spinlock_t*);
+
+/*
+ * spinlock_trylock() - Attempt to lock a spinlock
+ *
+ * SYNOPSIS
+ *  int spinlock_trylock(spinlock_t *lock);
+ *
+ * DESCRIPTION
+ *  The spinlock_trylock() function will attempt once to lock the
+ *  spinlock pointed to by `lock'. This function will not block.
+ *
+ * RETURN VALUE
+ *  0 the caller now holds the lock
+ *  * the spinlock could not be locked
+ */
+int spinlock_trylock(spinlock_t*);
+
+/*
+ * spinlock_unlock() - Unlock a spinlock
+ *
+ * SYNOPSIS
+ *  int spinlock_unlock(spinlock_t *lock);
+ *
+ * DESCRIPTION
+ *  The spinlock_unlock() function will unlock the spinlock pointed
+ *  to by `lock'. This function will unlock any spinlock regardless
+ *  of spinlock ownership, and the spinlock will always be unlocked
+ *  when this function returns.
+ *
+ * RETURN VALUE
+ *  0 the spinlock was not locked
+ *  * the spinlock was locked
+ */
+int spinlock_unlock(spinlock_t*);
+
+#endif /* __SPINLOCK_H */