AuroraRuntime/Source/Threading/Primitives/AuEvent.hpp
Jamie Reece Wilson 62b6fa20f8 [*] Update the copyright header of most of the primitives
[*] Fix generic mutex abs yield always returning true
2024-01-29 14:48:04 +00:00

73 lines
1.8 KiB
C++

/***
Copyright (C) 2021-2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuEvent.hpp
Date: 2021-6-12
Author: Reece
***/
#pragma once
#include "AuConditionVariable.Generic.hpp"
#include "AuConditionMutex.Generic.hpp"
namespace Aurora::Threading::Primitives
{
struct EventImpl final : IEvent
{
EventImpl(bool bTriggered, bool bAtomicRelease, bool bPermitMultipleTriggers);
~EventImpl();
bool Init();
bool LockMS(AuUInt64 timeout /*=0*/) override;
bool LockNS(AuUInt64 timeout /*=0*/) override;
bool LockAbsNS(AuUInt64 timeout /*=0*/) override;
bool TryLock() override;
void Reset() override;
void Set() override;
bool TrySet() override;
bool HasOSHandle(AuMach &mach) override;
bool HasLockImplementation() override;
void Lock() override;
void Unlock() override;
auline AuUInt32 *GetSleepCounter();
private:
bool AtomicIsEventSetLogicNoSpinNoLock();
ConditionMutexInternal mutex_; // must come first
ConditionVariableInternal condition_;
#if 0
const bool bAtomicRelease_ {};
const bool bPermitMultipleTriggers_ {};
bool bTriggered_ {};
#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);
#endif
};
}