2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: ConditionVariable.hpp
|
|
|
|
Date: 2021-6-9
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
A standard conditional variable tied to IConditionalMutex <br>
|
|
|
|
Multiple conditionals may use a common IConditionalMutex. <br>
|
|
|
|
Unlike the POSIX standard, <br>
|
|
|
|
1) we define no waitable as illegal <br>
|
|
|
|
2) conditional variables may not rebind their mutex
|
|
|
|
*/
|
2023-01-15 06:05:22 +00:00
|
|
|
struct IConditionVariable
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-08-16 08:47:54 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns the mutex the condvar was bound to
|
|
|
|
*/
|
2021-10-08 19:51:34 +00:00
|
|
|
virtual AuSPtr<IConditionMutex> GetMutex() = 0;
|
2023-08-16 08:47:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param uTimeoutMS timeout in milliseconds or zero for an indefinite amount of time
|
|
|
|
* @return
|
|
|
|
*/
|
2023-07-25 14:59:04 +00:00
|
|
|
virtual bool WaitForSignal(AuUInt32 uTimeoutMS = 0) = 0;
|
2023-08-16 08:47:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param uTimeoutMS timeout in nanoseconds or zero for an indefinite amount of time
|
|
|
|
* @return
|
|
|
|
*/
|
2023-07-25 14:59:04 +00:00
|
|
|
virtual bool WaitForSignalNS(AuUInt64 uTimeoutNS = 0) = 0;
|
2023-08-16 08:47:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wakes the count of currently sleeping threads without guaranteed respect for ordering.
|
|
|
|
* Assuming correctness of your mutex paths, this will wake all threads up-to your everyone-be-alert condition.
|
|
|
|
*/
|
2021-06-27 21:25:29 +00:00
|
|
|
virtual void Broadcast() = 0;
|
2023-08-16 08:47:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Schedules a single thread for wake up without guaranteed respect for ordering.
|
|
|
|
*/
|
2021-06-27 21:25:29 +00:00
|
|
|
virtual void Signal() = 0;
|
|
|
|
};
|
|
|
|
|
2023-08-16 08:47:54 +00:00
|
|
|
AUKN_SHARED_SOO2_NCM(ConditionVariable, IConditionVariable, kPrimitiveSizeCond,
|
|
|
|
((const AuSPtr<IConditionMutex>&, pMutex)),
|
|
|
|
const AuSPtr<IConditionMutex> &mutex);
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|