AuroraRuntime/Source/Threading/Primitives/AuEvent.hpp
Jamie Reece Wilson 48dc2e790b [+] IEvent::TrySet()
[+] New atomic logic for AuEvent. With this change, I can stop slandering it as the "shit primitive."
(it's still not the best it could be, but it's an improvement over what i had before)
2023-09-10 14:04:00 +01:00

69 lines
1.7 KiB
C++

/***
Copyright (C) 2021 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 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;
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;
};
AuUInt8 state;
};
union
{
struct
{
AuUInt8 bAtomicRelease_ : 1;
AuUInt8 bPermitMultipleTriggers_ : 1;
AuUInt8 bTriggered_ : 1;
};
AuUInt8 state_;
};
#endif
};
}