Add conditional acquisition parameter to RAII guard classes
All checks were successful
Builds / ExectOS (i686, debug) (push) Successful in 31s
Builds / ExectOS (amd64, debug) (push) Successful in 34s
Builds / ExectOS (amd64, release) (push) Successful in 58s
Builds / ExectOS (i686, release) (push) Successful in 55s

This commit is contained in:
2026-06-06 17:26:39 +02:00
parent f680830b53
commit cf25af23d1
2 changed files with 48 additions and 12 deletions

View File

@@ -19,18 +19,27 @@ namespace KE
{
private:
KSPIN_LOCK_QUEUE_LEVEL QueuedLockLevel;
BOOLEAN Owned;
public:
QueuedSpinLockGuard(IN OUT KSPIN_LOCK_QUEUE_LEVEL LockLevel)
QueuedSpinLockGuard(IN OUT KSPIN_LOCK_QUEUE_LEVEL LockLevel,
IN BOOLEAN Acquire = TRUE)
{
QueuedLockLevel = LockLevel;
Owned = Acquire;
if(Owned)
{
KE::SpinLock::AcquireQueuedSpinLock(QueuedLockLevel);
}
}
~QueuedSpinLockGuard()
{
if(Owned)
{
KE::SpinLock::ReleaseQueuedSpinLock(QueuedLockLevel);
}
}
QueuedSpinLockGuard(const QueuedSpinLockGuard&) = delete;
QueuedSpinLockGuard& operator=(const QueuedSpinLockGuard&) = delete;
@@ -40,18 +49,27 @@ namespace KE
{
private:
PKSPIN_LOCK Lock;
BOOLEAN Owned;
public:
SpinLockGuard(IN OUT PKSPIN_LOCK SpinLock)
SpinLockGuard(IN OUT PKSPIN_LOCK SpinLock,
IN BOOLEAN Acquire = TRUE)
{
Lock = SpinLock;
Owned = Acquire;
if(Owned)
{
KE::SpinLock::AcquireSpinLock(Lock);
}
}
~SpinLockGuard()
{
if(Owned)
{
KE::SpinLock::ReleaseSpinLock(Lock);
}
}
SpinLockGuard(const SpinLockGuard&) = delete;
SpinLockGuard& operator=(const SpinLockGuard&) = delete;

View File

@@ -27,18 +27,27 @@ namespace KE
{
private:
KRUNLEVEL PreviousRunLevel;
BOOLEAN Switched;
public:
LowerRunLevel(KRUNLEVEL RunLevel)
LowerRunLevel(IN KRUNLEVEL RunLevel,
IN BOOLEAN ChangeLevel = TRUE)
{
PreviousRunLevel = KE::RunLevel::GetCurrentRunLevel();
Switched = ChangeLevel;
if(Switched)
{
KE::RunLevel::LowerRunLevel(RunLevel);
}
}
~LowerRunLevel()
{
if(Switched)
{
KE::RunLevel::RaiseRunLevel(PreviousRunLevel);
}
}
LowerRunLevel(const LowerRunLevel&) = delete;
LowerRunLevel& operator=(const LowerRunLevel&) = delete;
@@ -48,18 +57,27 @@ namespace KE
{
private:
KRUNLEVEL PreviousRunLevel;
BOOLEAN Switched;
public:
RaiseRunLevel(KRUNLEVEL RunLevel)
RaiseRunLevel(IN KRUNLEVEL RunLevel,
IN BOOLEAN ChangeLevel = TRUE)
{
PreviousRunLevel = KE::RunLevel::GetCurrentRunLevel();
Switched = ChangeLevel;
if(Switched)
{
KE::RunLevel::RaiseRunLevel(RunLevel);
}
}
~RaiseRunLevel()
{
if(Switched)
{
KE::RunLevel::LowerRunLevel(PreviousRunLevel);
}
}
RaiseRunLevel(const RaiseRunLevel&) = delete;
RaiseRunLevel& operator=(const RaiseRunLevel&) = delete;