+#include <lunaix/kpreempt.h>
+
+static inline bool must_inline
+__mutex_check_owner(mutex_t* mutex)
+{
+ return mutex->owner == __current->pid;
+}
+
+static inline void must_inline
+__mutext_lock(mutex_t* mutex)
+{
+ while (atomic_load(&mutex->lk)) {
+ preempt_current();
+ }
+
+ atomic_fetch_add(&mutex->lk, 1);
+ mutex->owner = __current->pid;
+}
+
+static inline void must_inline
+__mutext_unlock(mutex_t* mutex)
+{
+ if (__mutex_check_owner(mutex))
+ atomic_fetch_sub(&mutex->lk, 1);
+}