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

Kernel: Tidy up the ScopedCritical class a little bit

This commit is contained in:
Andreas Kling 2020-07-06 11:27:07 +02:00
parent 0d851b1930
commit 3e0020e67d

View file

@ -804,15 +804,10 @@ public:
void set_thread_specific(u8* data, size_t len); void set_thread_specific(u8* data, size_t len);
}; };
class ScopedCritical class ScopedCritical {
{ AK_MAKE_NONCOPYABLE(ScopedCritical);
u32 m_prev_flags;
bool m_valid;
public: public:
ScopedCritical(const ScopedCritical&) = delete;
ScopedCritical& operator=(const ScopedCritical&) = delete;
ScopedCritical() ScopedCritical()
{ {
m_valid = true; m_valid = true;
@ -827,24 +822,24 @@ public:
} }
} }
ScopedCritical(ScopedCritical&& from): ScopedCritical(ScopedCritical&& from)
m_prev_flags(from.m_prev_flags), : m_prev_flags(exchange(from.m_prev_flags, 0))
m_valid(from.m_valid) , m_valid(exchange(from.m_valid, false))
{ {
from.m_prev_flags = 0;
from.m_valid = false;
} }
ScopedCritical& operator=(ScopedCritical&& from) ScopedCritical& operator=(ScopedCritical&& from)
{ {
if (&from != this) { if (&from != this) {
m_prev_flags = from.m_prev_flags; m_prev_flags = exchange(from.m_prev_flags, 0);
m_valid = from.m_valid; m_valid = exchange(from.m_valid, false);
from.m_prev_flags = 0;
from.m_valid = false;
} }
return *this; return *this;
} }
private:
u32 m_prev_flags { 0 };
bool m_valid { false };
}; };
struct TrapFrame { struct TrapFrame {