AuroraRuntime/Source/Threading/Primitives/AuEvent.hpp

73 lines
1.8 KiB
C++
Raw Normal View History

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
{
struct EventImpl final : IEvent
2021-06-27 21:25:29 +00:00
{
EventImpl(bool bTriggered, bool bAtomicRelease, bool bPermitMultipleTriggers);
2021-06-27 21:25:29 +00:00
~EventImpl();
bool Init();
bool LockMS(AuUInt64 timeout /*=0*/) override;
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;
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:
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
const bool bAtomicRelease_ {};
const bool bPermitMultipleTriggers_ {};
bool bTriggered_ {};
2023-03-17 15:40:15 +00:00
#else
union EventBits
{
struct
{
AuUInt8 bAtomicRelease : 1;
AuUInt8 bPermitMultipleTriggers : 1;
AuUInt8 bTriggered : 1;
};
AuUInt32 state;
};
union
{
struct
{
AuUInt8 bAtomicRelease_ : 1;
AuUInt8 bPermitMultipleTriggers_ : 1;
AuUInt8 bTriggered_ : 1;
};
AuUInt32 state_;
};
void DoSignal(const EventBits &bits);
2023-03-17 15:40:15 +00:00
#endif
2021-06-27 21:25:29 +00:00
};
}