Files
banan-os/kernel/include/kernel/Lock/LockGuard.h
Bananymous eecdad50a6 Kernel: Fix most of mutex + block race conditions
All block functions now take an optional mutex parameter that is
atomically unlocked instead of having the user unlock it before hand.
This prevents a ton of race conditions everywhere in the code!
2025-06-06 03:59:22 +03:00

33 lines
346 B
C++

#pragma once
#include <BAN/NoCopyMove.h>
#include <stdint.h>
namespace Kernel
{
template<typename Lock>
class LockGuard
{
BAN_NON_COPYABLE(LockGuard);
BAN_NON_MOVABLE(LockGuard);
public:
LockGuard(Lock& lock)
: m_lock(lock)
{
m_lock.lock();
}
~LockGuard()
{
m_lock.unlock();
}
private:
Lock& m_lock;
};
}