[+] IRWLock::CheckSelfThreadIsWriter

This commit is contained in:
Reece Wilson 2023-12-01 01:12:18 +00:00
parent 5ec28735ed
commit 43583a1748
3 changed files with 24 additions and 7 deletions

View File

@ -13,7 +13,8 @@ namespace Aurora::Threading::Primitives
{
/**
* @brief Returns a complete IWaitable interface for reantrant access to the protected resources.
* Once a thread takes exclusive access of the resource, only it shall pass read
* Once a thread takes exclusive access of the resource, only it shall pass read. Noting this
* is critical section behaviour, not mutex behaviour.
* @return
*/
virtual IWaitable *AsReadable() = 0;
@ -39,12 +40,19 @@ namespace Aurora::Threading::Primitives
* @return
*/
virtual bool DowngradeWriteToRead() = 0;
/**
* @brief Checks if the current thread has acquired a critical-section lock on the mutually exclusive resource
* @return
*/
virtual bool CheckSelfThreadIsWriter() = 0;
};
/// Allows AsReadable entrancy as AsWritable lock
/// Allows AsReadable() holder entrancy as AsWritable() lock
/// Check CheckSelfThreadIsWriter() before any lock guards, if non-reentrant mutual exclusion is desired.
AUKN_SHARED_SOO_NCM(RWLock, IRWLock, kPrimitiveSizeRWLock);
/// Allows AsWritable reentrancy, and allows AsReadable entrancy as AsWritable lock
/// Allows AsWritable() holder reentrancy, and allows AsReadable() holder entrancy as AsWritable() lock
AUKN_SHARED_SOO_NCM(RWRenterableLock, IRWLock, kPrimitiveSizeRWLock);
}

View File

@ -934,6 +934,13 @@ namespace Aurora::Threading::Primitives
return &this->write_;
}
template<bool bIsWriteRecursionAllowed>
bool RWLockImpl<bIsWriteRecursionAllowed>::CheckSelfThreadIsWriter()
{
return this->reentrantWriteLockHandle_ == GetThreadCookie();
}
AUKN_SYM IRWLock *RWLockNew()
{
return _new RWLockImpl<false>();

View File

@ -90,6 +90,8 @@ namespace Aurora::Threading::Primitives
IWaitable *AsReadable() override;
IWaitable *AsWritable() override;
bool CheckSelfThreadIsWriter() override;
auline ConditionVariableInternal &GetCondition();
auline ConditionVariableInternal &GetConditionWriter();