AuroraRuntime/Include/Aurora/Threading/Primitives/Event.hpp

40 lines
1.3 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Event.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Threading::Primitives
{
/**
Event synchronization primitive
*/
struct IEvent : IWaitable
{
// Unlike the other types, unlock is always a nop. It makes sense the caller to not automatically reset an event, contrary to `::Lock(); work; ::Unlock();`
// Ordinarily, we would expect the thread responsible for work processing to ::Lock/::Unlock (maybe ::Reset()), and the dispatching thread to ::Reset and ::Set.
inline void Wait()
{
Lock();
}
inline void Wait(AuUInt32 ms)
{
LockMS(ms);
}
virtual void Reset() = 0;
virtual void Set() = 0;
virtual bool TrySet() = 0; // returns false on bPermitMultipleTriggers violation
};
AUKN_SHARED_SOO2_NCM(Event, IEvent, kPrimitiveSizeEvent,
((bool, bTriggered), (bool, bAtomicRelease), (bool, bPermitMultipleTriggers)),
bool bInitiallyTriggerd = false,
bool bAtomicRelease = true,
bool bPermitMultipleTriggers = false);
}