AuroraRuntime/Source/IO/IPC/AuIPCPrimitives.Linux.hpp

75 lines
1.9 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIPCPrimitives.Linux.hpp
Date: 2022-4-13
Author: Reece
***/
#pragma once
#include "IPC.hpp"
#include "AuIPCHandle.hpp"
#include <Source/IO/Loop/LSEvent.hpp>
#include <Source/IO/Loop/LSSemaphore.hpp>
#include <Source/IO/Loop/LSMutex.hpp>
#include <Source/IO/IPC/IPC.hpp>
#include <Source/IO/IPC/AuIPCHandle.hpp>
namespace Aurora::IO::IPC
{
#if !defined(IMPLEMENT_HANDLE)
#define IMPLEMENT_HANDLE \
IPC::IPCHandle handle_; \
AuString ExportToString() override \
{ \
return handle_.ToString(); \
}
#endif
struct IPCEventProxy : IPCEvent, Loop::ILoopSourceEx
{
IPCEventProxy(bool triggered, bool atomicRelease);
IPCEventProxy(int handle, bool triggered, bool atomicRelease);
~IPCEventProxy();
PROXY_INTERNAL_INTERFACE(event_)
IMPLEMENT_HANDLE
bool Set() override;
bool Reset() override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;
private:
Loop::LSEvent event_;
};
struct IPCSemaphoreProxy : IPCSemaphore, Loop::ILoopSourceEx
{
IPCSemaphoreProxy(AuUInt32 initialCount);
IPCSemaphoreProxy(int handle, int tag);
~IPCSemaphoreProxy();
PROXY_INTERNAL_INTERFACE(semaphore_)
IMPLEMENT_HANDLE
bool AddOne() override;
bool AddMany(AuUInt32 uCount) override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;
private:
Loop::LSSemaphore semaphore_;
};
AuSPtr<IPCEvent> ImportEventEx(const IPCToken &token);
}