Pārlūkot izejas kodu

fix(lock): labels may be defined multiple times

greatbridf 2 gadi atpakaļ
vecāks
revīzija
f992f91617
3 mainītis faili ar 28 papildinājumiem un 36 dzēšanām
  1. 1 1
      CMakeLists.txt
  2. 0 35
      include/types/lock.h
  3. 27 0
      include/types/lock.hpp

+ 1 - 1
CMakeLists.txt

@@ -100,7 +100,7 @@ set(KERNEL_MAIN_SOURCES src/fs/fat.cpp
                         include/types/allocator.hpp
                         include/types/cplusplus.hpp
                         include/types/list.hpp
-                        include/types/lock.h
+                        include/types/lock.hpp
                         include/types/string.hpp
                         include/types/vector.hpp
                         include/kernel_main.h

+ 0 - 35
include/types/lock.h

@@ -1,35 +0,0 @@
-#pragma once
-
-#include <types/stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static inline void spin_lock(uint32_t volatile* lock_addr)
-{
-    asm volatile(
-            "_spin:\n\t\
-             movl $1, %%eax\n\t\
-             xchgl %%eax, (%0)\n\t\
-             test $0, %%eax\n\t\
-             jne _spin\n\t\
-            "
-            : "=r" (lock_addr)
-            : "0"  (lock_addr)
-            : "eax", "memory"
-            );
-}
-
-static inline void spin_unlock(uint32_t volatile* lock_addr)
-{
-    asm volatile("movl $0, %%eax\nxchgl %%eax, (%0)"
-                 :
-                 : "r"  (lock_addr)
-                 : "eax", "memory"
-                 );
-}
-
-#ifdef __cplusplus
-}
-#endif

+ 27 - 0
include/types/lock.hpp

@@ -0,0 +1,27 @@
+#pragma once
+
+#include <types/stdint.h>
+
+inline void spin_lock(uint32_t volatile* lock_addr)
+{
+    asm volatile(
+        "0:\n\t\
+         movl $1, %%eax\n\t\
+         xchgl %%eax, (%0)\n\t\
+         test $0, %%eax\n\t\
+         jne 0\n\t\
+        "
+        :
+        : "r"(lock_addr)
+        : "eax", "memory");
+}
+
+inline void spin_unlock(uint32_t volatile* lock_addr)
+{
+    asm volatile(
+        "movl $0, %%eax\n\
+         xchgl %%eax, (%0)"
+        :
+        : "r"(lock_addr)
+        : "eax", "memory");
+}