/*** 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. * You must be careful to consider how this is used to prevent dead-locks * @param timeout in relative nanoseconds * @return */ virtual bool UpgradeReadToWrite(AuUInt64 timeout) = 0; /** * @brief Reverses UpgradeReadToWrite. * @return */ virtual bool DowngradeWriteToRead() = 0; }; /// Allows AsReadable entrancy as AsWritable lock AUKN_SHARED_SOO_NCM(RWLock, IRWLock, kPrimitiveSizeRWLock); /// Allows AsWritable reentrancy, and allows AsReadable entrancy as AsWritable lock AUKN_SHARED_SOO_NCM(RWRenterableLock, IRWLock, kPrimitiveSizeRWLock); }