mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-09 08:38:37 +00:00
4314a8f3e5
* Add support for events, move concept of domains to IpcService * Support waiting for KThread, remove some test code, other tweaks * Use move handle on NIFM since I can't test that now, it's better to leave it how it was
85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using ChocolArm64.State;
|
|
using Ryujinx.Core.OsHle.Handles;
|
|
|
|
using static Ryujinx.Core.OsHle.ErrorCode;
|
|
|
|
namespace Ryujinx.Core.OsHle.Svc
|
|
{
|
|
partial class SvcHandler
|
|
{
|
|
private void SvcArbitrateLock(AThreadState ThreadState)
|
|
{
|
|
int OwnerThreadHandle = (int)ThreadState.X0;
|
|
long MutexAddress = (long)ThreadState.X1;
|
|
int RequestingThreadHandle = (int)ThreadState.X2;
|
|
|
|
KThread RequestingThread = Process.HandleTable.GetData<KThread>(RequestingThreadHandle);
|
|
|
|
Mutex M = new Mutex(Process, MutexAddress, OwnerThreadHandle);
|
|
|
|
M = Ns.Os.Mutexes.GetOrAdd(MutexAddress, M);
|
|
|
|
M.WaitForLock(RequestingThread, RequestingThreadHandle);
|
|
|
|
ThreadState.X0 = 0;
|
|
}
|
|
|
|
private void SvcArbitrateUnlock(AThreadState ThreadState)
|
|
{
|
|
long MutexAddress = (long)ThreadState.X0;
|
|
|
|
if (Ns.Os.Mutexes.TryGetValue(MutexAddress, out Mutex M))
|
|
{
|
|
M.Unlock();
|
|
}
|
|
|
|
ThreadState.X0 = 0;
|
|
}
|
|
|
|
private void SvcWaitProcessWideKeyAtomic(AThreadState ThreadState)
|
|
{
|
|
long MutexAddress = (long)ThreadState.X0;
|
|
long CondVarAddress = (long)ThreadState.X1;
|
|
int ThreadHandle = (int)ThreadState.X2;
|
|
long Timeout = (long)ThreadState.X3;
|
|
|
|
KThread Thread = Process.HandleTable.GetData<KThread>(ThreadHandle);
|
|
|
|
Mutex M = new Mutex(Process, MutexAddress, ThreadHandle);
|
|
|
|
M = Ns.Os.Mutexes.GetOrAdd(MutexAddress, M);
|
|
|
|
M.GiveUpLock(ThreadHandle);
|
|
|
|
CondVar Cv = new CondVar(Process, CondVarAddress, Timeout);
|
|
|
|
Cv = Ns.Os.CondVars.GetOrAdd(CondVarAddress, Cv);
|
|
|
|
if (!Cv.WaitForSignal(Thread))
|
|
{
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.Timeout);
|
|
|
|
return;
|
|
}
|
|
|
|
M.WaitForLock(Thread, ThreadHandle);
|
|
|
|
ThreadState.X0 = 0;
|
|
}
|
|
|
|
private void SvcSignalProcessWideKey(AThreadState ThreadState)
|
|
{
|
|
long CondVarAddress = (long)ThreadState.X0;
|
|
int Count = (int)ThreadState.X1;
|
|
|
|
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
|
|
|
|
if (Ns.Os.CondVars.TryGetValue(CondVarAddress, out CondVar Cv))
|
|
{
|
|
Cv.SetSignal(CurrThread, Count);
|
|
}
|
|
|
|
ThreadState.X0 = 0;
|
|
}
|
|
}
|
|
} |