AuroraRuntime/Include/Aurora/Loop/Loop.hpp

113 lines
2.8 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Loop.hpp
Date: 2021-8-21
Author: Reece
***/
#pragma once
namespace Aurora::Loop
{
enum class ELoopSource
{
eSourceInternalReserved1,
eSourceInternalReserved2,
eSourceInternalReserved3,
eSourceInternalReserved4,
// generic
eSourceSemaphore,
eSourceCV,
eSourceEvent,
eSourceMutex,
eSourceSRW,
eSourceTimer,
eSourceAIO,
eSourceHandle,
// Specific to the runtime subsystem
eSourceAsync,
// glib oses only
eSourceGlib,
// window messge loops
eSourceApple,
eSourceX11,
eSourceWin32
};
class ILoopSource
{
public:
virtual bool IsSignaled() = 0;
virtual ELoopSource GetType() = 0;
};
AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleObjects(AuList<AuSPtr<ILoopSource>>, AuUInt32 timeout);
class ILSSemaphore : public ILoopSource
{
public:
virtual bool AddOne() = 0;
};
class ILSEvent : public ILoopSource
{
public:
virtual bool Reset() = 0;
};
class ILSMutex : public ILoopSource
{
public:
virtual bool Unlock() = 0;
};
class IConditionVar : public ILoopSource
{
public:
virtual bool Signal() = 0;
virtual bool Broadcast() = 0;
};
class ITimer : public ILoopSource
{
public:
virtual void UpdateTime(AuUInt64 absTimeMs) = 0;
};
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Aurora::Threading::IWaitable> &primitive);
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<ILSMutex> &source);
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absTimeMs);
AUKN_SYM AuSPtr<ILSMutex> NewLSMutex();
AUKN_SYM AuSPtr<ILSEvent> NewLSEvent(bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false);
AUKN_SYM AuSPtr<ILSSemaphore> NewLSSemaphore(AuUInt32 initialCount = 0);
AUKN_SYM AuSPtr<ILoopSource> NewLSOSHandle(AuUInt);
AUKN_SYM AuSPtr<ILoopSource> NewLSAsync();
AUKN_SYM AuSPtr<ILoopSource> NewLSWin32Source();
AUKN_SYM AuSPtr<ILoopSource> NewLSAppleSource();
#if defined(X_PROTOCOL)
static AuSPtr<ILoopSource> NewLSX11(Display *display)
{
return NewLSOSHandle(ConnectionNumber(display));
}
#endif
#if defined(AURORA_IS_POSIX_DERIVED)
static AuSPtr<ILoopSource> NewLSFd(int fd)
{
return NewLSOSHandle(fd);
}
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
static AuSPtr<ILoopSource> NewLSHandle(HANDLE handle)
{
return NewLSOSHandle(reinterpret_cast<AuUInt>(handle));
}
#endif
}