Implement RAII guards for exclusive and shared push locks
All checks were successful
Builds / ExectOS (i686, debug) (push) Successful in 37s
Builds / ExectOS (amd64, debug) (push) Successful in 47s
Builds / ExectOS (i686, release) (push) Successful in 36s
Builds / ExectOS (amd64, release) (push) Successful in 46s

This commit is contained in:
2026-07-10 08:27:09 +02:00
parent c7b257dfc4
commit f51c7a5ce5
2 changed files with 62 additions and 4 deletions

View File

@@ -12,6 +12,7 @@
#include <xtos.hh> #include <xtos.hh>
#include <ke/kthread.hh> #include <ke/kthread.hh>
#include <ke/proc.hh> #include <ke/proc.hh>
#include <ke/pushlock.hh>
#include <ke/spinlock.hh> #include <ke/spinlock.hh>
@@ -52,6 +53,66 @@ namespace KE
CriticalRegionGuard& operator=(const CriticalRegionGuard&) = delete; CriticalRegionGuard& operator=(const CriticalRegionGuard&) = delete;
}; };
class PushLockExclusiveGuard
{
private:
PKPUSH_LOCK Lock;
BOOLEAN Owned;
public:
PushLockExclusiveGuard(IN PKPUSH_LOCK PushLock,
IN BOOLEAN Acquire = TRUE)
{
Lock = PushLock;
Owned = Acquire;
if(Owned)
{
KE::PushLock::AcquireExclusivePushLock(Lock);
}
}
~PushLockExclusiveGuard()
{
if(Owned)
{
KE::PushLock::ReleaseExclusivePushLock(Lock);
}
}
PushLockExclusiveGuard(const PushLockExclusiveGuard&) = delete;
PushLockExclusiveGuard& operator=(const PushLockExclusiveGuard&) = delete;
};
class PushLockSharedGuard
{
private:
PKPUSH_LOCK Lock;
BOOLEAN Owned;
public:
PushLockSharedGuard(IN PKPUSH_LOCK PushLock,
IN BOOLEAN Acquire = TRUE)
{
Lock = PushLock;
Owned = Acquire;
if(Owned)
{
KE::PushLock::AcquireSharedPushLock(Lock);
}
}
~PushLockSharedGuard()
{
if(Owned)
{
KE::PushLock::ReleaseSharedPushLock(Lock);
}
}
PushLockSharedGuard(const PushLockSharedGuard&) = delete;
PushLockSharedGuard& operator=(const PushLockSharedGuard&) = delete;
};
class QueuedSpinLockGuard class QueuedSpinLockGuard
{ {
private: private:

View File

@@ -841,13 +841,10 @@ OB::LifeCycle::DeleteObject(IN PVOID Object,
{ {
/* Acquire exclusive access to the object type tracking list */ /* Acquire exclusive access to the object type tracking list */
KE::CriticalRegionGuard CriticalRegion; KE::CriticalRegionGuard CriticalRegion;
KE::PushLock::AcquireExclusivePushLock(&ObjectType->TypeLock); KE::PushLockExclusiveGuard PushLock(&ObjectType->TypeLock);
/* Unlink the object from the creator type list */ /* Unlink the object from the creator type list */
RTL::LinkedList::RemoveEntryList(&CreatorInfo->TypeList); RTL::LinkedList::RemoveEntryList(&CreatorInfo->TypeList);
/* Release the object type tracking list */
KE::PushLock::ReleaseExclusivePushLock(&ObjectType->TypeLock);
} }
/* Check if the object has an allocated name buffer */ /* Check if the object has an allocated name buffer */