mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-09-11 18:28:50 +02:00
* IPC refactor part 3 + 4: New server HIPC message processor with source generator based serialization * Make types match on calls to AlignUp/AlignDown * Formatting * Address some PR feedback * Move BitfieldExtensions to Ryujinx.Common.Utilities and consolidate implementations * Rename Reader/Writer to SpanReader/SpanWriter and move to Ryujinx.Common.Memory * Implement EventType * Address more PR feedback * Log request processing errors since they are not normal * Rename waitable to multiwait and add missing lock * PR feedback * Ac_K PR feedback
136 lines
3.6 KiB
C#
136 lines
3.6 KiB
C#
using Ryujinx.Horizon.Common;
|
|
using System;
|
|
|
|
namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
|
|
{
|
|
static class InterProcessEventImpl
|
|
{
|
|
public static Result Create(out int writableHandle, out int readableHandle)
|
|
{
|
|
Result result = HorizonStatic.Syscall.CreateEvent(out writableHandle, out readableHandle);
|
|
|
|
if (result == KernelResult.OutOfResource)
|
|
{
|
|
return OsResult.OutOfResource;
|
|
}
|
|
|
|
result.AbortOnFailure();
|
|
|
|
return Result.Success;
|
|
}
|
|
|
|
public static void Close(int handle)
|
|
{
|
|
if (handle != 0)
|
|
{
|
|
HorizonStatic.Syscall.CloseHandle(handle).AbortOnFailure();
|
|
}
|
|
}
|
|
|
|
public static void Signal(int handle)
|
|
{
|
|
HorizonStatic.Syscall.SignalEvent(handle).AbortOnFailure();
|
|
}
|
|
|
|
public static void Clear(int handle)
|
|
{
|
|
HorizonStatic.Syscall.ClearEvent(handle).AbortOnFailure();
|
|
}
|
|
|
|
public static void Wait(int handle, bool autoClear)
|
|
{
|
|
Span<int> handles = stackalloc int[1];
|
|
|
|
handles[0] = handle;
|
|
|
|
while (true)
|
|
{
|
|
Result result = HorizonStatic.Syscall.WaitSynchronization(out _, handles, -1L);
|
|
|
|
if (result == Result.Success)
|
|
{
|
|
if (autoClear)
|
|
{
|
|
result = HorizonStatic.Syscall.ResetSignal(handle);
|
|
|
|
if (result == KernelResult.InvalidState)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
result.AbortOnFailure();
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
result.AbortUnless(KernelResult.Cancelled);
|
|
}
|
|
}
|
|
|
|
public static bool TryWait(int handle, bool autoClear)
|
|
{
|
|
if (autoClear)
|
|
{
|
|
return HorizonStatic.Syscall.ResetSignal(handle) == Result.Success;
|
|
}
|
|
|
|
Span<int> handles = stackalloc int[1];
|
|
|
|
handles[0] = handle;
|
|
|
|
while (true)
|
|
{
|
|
Result result = HorizonStatic.Syscall.WaitSynchronization(out _, handles, 0);
|
|
|
|
if (result == Result.Success)
|
|
{
|
|
return true;
|
|
}
|
|
else if (result == KernelResult.TimedOut)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
result.AbortUnless(KernelResult.Cancelled);
|
|
}
|
|
}
|
|
|
|
public static bool TimedWait(int handle, bool autoClear, TimeSpan timeout)
|
|
{
|
|
Span<int> handles = stackalloc int[1];
|
|
|
|
handles[0] = handle;
|
|
|
|
long timeoutNs = timeout.Milliseconds * 1000000L;
|
|
|
|
while (true)
|
|
{
|
|
Result result = HorizonStatic.Syscall.WaitSynchronization(out _, handles, timeoutNs);
|
|
|
|
if (result == Result.Success)
|
|
{
|
|
if (autoClear)
|
|
{
|
|
result = HorizonStatic.Syscall.ResetSignal(handle);
|
|
|
|
if (result == KernelResult.InvalidState)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
result.AbortOnFailure();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else if (result == KernelResult.TimedOut)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
result.AbortUnless(KernelResult.Cancelled);
|
|
}
|
|
}
|
|
}
|
|
}
|