1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

AK: Add Atomic.h

Use gcc built-in atomics
This commit is contained in:
Tom 2019-10-12 11:17:34 -06:00 committed by Andreas Kling
parent 2530378f59
commit b0773a8ea6
6 changed files with 606 additions and 53 deletions

View file

@ -2,6 +2,7 @@
#include <AK/Assertions.h>
#include <AK/Types.h>
#include <AK/Atomic.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/KSyms.h>
#include <Kernel/Scheduler.h>
@ -9,17 +10,6 @@
class Thread;
extern Thread* current;
static inline u32 CAS(volatile u32* mem, u32 newval, u32 oldval)
{
u32 ret;
asm volatile(
"cmpxchgl %2, %1"
: "=a"(ret), "+m"(*mem)
: "r"(newval), "0"(oldval)
: "cc", "memory");
return ret;
}
class Lock {
public:
Lock(const char* name = nullptr)
@ -35,7 +25,7 @@ public:
const char* name() const { return m_name; }
private:
volatile u32 m_lock { 0 };
Atomic<bool> m_lock { false };
u32 m_level { 0 };
Thread* m_holder { nullptr };
const char* m_name { nullptr };