2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
File: AuEvent.hpp
|
2021-06-27 21:25:29 +00:00
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-29 00:02:56 +00:00
|
|
|
#include "AuConditionVariable.Generic.hpp"
|
|
|
|
#include "AuConditionMutex.Generic.hpp"
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
2023-08-19 10:41:37 +00:00
|
|
|
struct EventImpl final : IEvent
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-03-13 23:57:32 +00:00
|
|
|
EventImpl(bool bTriggered, bool bAtomicRelease, bool bPermitMultipleTriggers);
|
2021-06-27 21:25:29 +00:00
|
|
|
~EventImpl();
|
|
|
|
|
|
|
|
bool Init();
|
2023-04-03 07:21:44 +00:00
|
|
|
bool LockMS(AuUInt64 timeout /*=0*/) override;
|
2023-03-12 15:27:28 +00:00
|
|
|
bool LockNS(AuUInt64 timeout /*=0*/) override;
|
2023-09-10 14:03:12 +00:00
|
|
|
bool LockAbsNS(AuUInt64 timeout /*=0*/) override;
|
2021-06-27 21:25:29 +00:00
|
|
|
bool TryLock() override;
|
|
|
|
void Reset() override;
|
|
|
|
void Set() override;
|
2023-09-10 13:00:18 +00:00
|
|
|
bool TrySet() override;
|
2021-06-27 21:25:29 +00:00
|
|
|
bool HasOSHandle(AuMach &mach) override;
|
|
|
|
bool HasLockImplementation() override;
|
|
|
|
void Lock() override;
|
|
|
|
void Unlock() override;
|
2023-09-10 14:03:12 +00:00
|
|
|
auline AuUInt32 *GetSleepCounter();
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
private:
|
2023-09-10 13:00:18 +00:00
|
|
|
bool AtomicIsEventSetLogicNoSpinNoLock();
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2023-08-21 16:34:24 +00:00
|
|
|
ConditionMutexInternal mutex_; // must come first
|
|
|
|
ConditionVariableInternal condition_;
|
2023-03-17 15:40:15 +00:00
|
|
|
|
|
|
|
#if 0
|
2023-03-13 23:57:32 +00:00
|
|
|
const bool bAtomicRelease_ {};
|
|
|
|
const bool bPermitMultipleTriggers_ {};
|
|
|
|
bool bTriggered_ {};
|
2023-03-17 15:40:15 +00:00
|
|
|
#else
|
2023-09-10 13:00:18 +00:00
|
|
|
|
|
|
|
union EventBits
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
AuUInt8 bAtomicRelease : 1;
|
|
|
|
AuUInt8 bPermitMultipleTriggers : 1;
|
|
|
|
AuUInt8 bTriggered : 1;
|
|
|
|
};
|
2023-09-10 17:10:36 +00:00
|
|
|
AuUInt32 state;
|
2023-09-10 13:00:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
AuUInt8 bAtomicRelease_ : 1;
|
|
|
|
AuUInt8 bPermitMultipleTriggers_ : 1;
|
|
|
|
AuUInt8 bTriggered_ : 1;
|
|
|
|
};
|
|
|
|
|
2023-09-10 17:10:36 +00:00
|
|
|
AuUInt32 state_;
|
2023-09-10 13:00:18 +00:00
|
|
|
};
|
|
|
|
|
2023-09-10 13:50:59 +00:00
|
|
|
|
|
|
|
void DoSignal(const EventBits &bits);
|
2023-03-17 15:40:15 +00:00
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
};
|
|
|
|
}
|