Implement RAII guards for exclusive and shared push locks
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <xtos.hh>
|
||||
#include <ke/kthread.hh>
|
||||
#include <ke/proc.hh>
|
||||
#include <ke/pushlock.hh>
|
||||
#include <ke/spinlock.hh>
|
||||
|
||||
|
||||
@@ -52,6 +53,66 @@ namespace KE
|
||||
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
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -841,13 +841,10 @@ OB::LifeCycle::DeleteObject(IN PVOID Object,
|
||||
{
|
||||
/* Acquire exclusive access to the object type tracking list */
|
||||
KE::CriticalRegionGuard CriticalRegion;
|
||||
KE::PushLock::AcquireExclusivePushLock(&ObjectType->TypeLock);
|
||||
KE::PushLockExclusiveGuard PushLock(&ObjectType->TypeLock);
|
||||
|
||||
/* Unlink the object from the creator type list */
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user