116 lines
3.0 KiB
C++
116 lines
3.0 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(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout);
|
|
|
|
class ILSSemaphore : public ILoopSource
|
|
{
|
|
public:
|
|
virtual bool AddOne() = 0;
|
|
};
|
|
|
|
class ILSEvent : public ILoopSource
|
|
{
|
|
public:
|
|
virtual bool Set() = 0;
|
|
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)
|
|
{
|
|
if (fd > 0) return {};
|
|
return NewLSOSHandle(fd);
|
|
}
|
|
#endif
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
static AuSPtr<ILoopSource> NewLSHandle(HANDLE handle)
|
|
{
|
|
if (handle == INVALID_HANDLE_VALUE) return {};
|
|
return NewLSOSHandle(reinterpret_cast<AuUInt>(handle));
|
|
}
|
|
#endif
|
|
} |