44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: RWLock.hpp
|
|
Date: 2021-6-9
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
{
|
|
struct IRWLock
|
|
{
|
|
/**
|
|
* @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
|
|
* @return
|
|
*/
|
|
virtual IWaitable *AsReadable() = 0;
|
|
|
|
/**
|
|
* @brief Returns a complete IWaitable interface for exclusive thread access to the protected resources
|
|
*
|
|
* @return
|
|
*/
|
|
virtual IWaitable *AsWritable() = 0;
|
|
|
|
/**
|
|
* @brief Allows for read-to-write upgrades when the decision to esclate is made based upon a shared resource
|
|
* which would be lost by unlocking and relocking in exclusive mode
|
|
* @param timeout
|
|
* @return
|
|
*/
|
|
virtual bool UpgradeReadToWrite(AuUInt64 timeout) = 0;
|
|
|
|
/**
|
|
* @brief Reverses UpgradeReadToWrite. Helps maintain AU_TRY_LOCK lock guards.
|
|
* @return
|
|
*/
|
|
virtual bool DowngradeWriteToRead() = 0;
|
|
};
|
|
|
|
AUKN_SHARED_API(RWLock, IRWLock);
|
|
} |