123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #pragma once
- #include "Time.h"
- #include "Lock.h"
- #include <cstdint>
- #if PLATFORM_FUTEX_NATIVE_SUPPORT
- #include "Internal/ConditionVariableData_FutexBased.inl.h"
- #else
- #include "Internal/ConditionVariableData_SemaphoreBased.inl.h"
- #endif
- namespace baselib
- {
- BASELIB_CPP_INTERFACE
- {
-
-
-
-
-
-
-
-
-
-
- class ConditionVariable
- {
- public:
-
- ConditionVariable(const ConditionVariable& other) = delete;
- ConditionVariable& operator=(const ConditionVariable& other) = delete;
-
- ConditionVariable(ConditionVariable&& other) = delete;
- ConditionVariable& operator=(ConditionVariable&& other) = delete;
-
- ConditionVariable(Lock& lock) : m_Lock(lock)
- {}
-
-
-
- ~ConditionVariable()
- {
- BaselibAssert(!m_Data.HasWaiters(), "Destruction is not allowed when there are still threads waiting on the condition variable.");
- NotifyAll();
- }
-
-
-
-
-
- inline void Wait();
-
-
-
-
-
-
-
-
-
-
- inline bool TimedWait(const timeout_ms timeoutInMilliseconds);
-
-
-
-
-
- inline void Notify(uint16_t count);
-
-
-
- inline void NotifyAll()
- {
- Notify(std::numeric_limits<uint16_t>::max());
- }
- private:
- Lock& m_Lock;
- detail::ConditionVariableData m_Data;
- };
- }
- }
- #if PLATFORM_FUTEX_NATIVE_SUPPORT
- #include "Internal/ConditionVariable_FutexBased.inl.h"
- #else
- #include "Internal/ConditionVariable_SemaphoreBased.inl.h"
- #endif
|