/*** 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; }; /// Allows AsReadable entrancy as AsWritable lock AUKN_SHARED_SOO(RWLock, IRWLock, kPrimitiveSizeRWLock); /// Allows AsWritable reentrancy, and allows AsReadable entrancy as AsWritable lock AUKN_SHARED_SOO(RWRenterableLock, IRWLock, kPrimitiveSizeRWLock); }