2018-02-05 00:08:20 +01:00
|
|
|
using ChocolArm64.State;
|
|
|
|
using Ryujinx.OsHle.Handles;
|
|
|
|
|
|
|
|
namespace Ryujinx.OsHle.Svc
|
|
|
|
{
|
|
|
|
partial class SvcHandler
|
|
|
|
{
|
2018-02-14 03:43:08 +01:00
|
|
|
private void SvcArbitrateLock(ARegisters Registers)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
int OwnerThreadHandle = (int)Registers.X0;
|
|
|
|
long MutexAddress = (long)Registers.X1;
|
|
|
|
int RequestingThreadHandle = (int)Registers.X2;
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
HThread RequestingThread = Ns.Os.Handles.GetData<HThread>(RequestingThreadHandle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
Mutex M = new Mutex(Process, MutexAddress, OwnerThreadHandle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
M = Ns.Os.Mutexes.GetOrAdd(MutexAddress, M);
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
M.WaitForLock(RequestingThread, RequestingThreadHandle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Registers.X0 = (int)SvcResult.Success;
|
|
|
|
}
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
private void SvcArbitrateUnlock(ARegisters Registers)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
long MutexAddress = (long)Registers.X0;
|
|
|
|
|
|
|
|
if (Ns.Os.Mutexes.TryGetValue(MutexAddress, out Mutex M))
|
|
|
|
{
|
|
|
|
M.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
Registers.X0 = (int)SvcResult.Success;
|
|
|
|
}
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
private void SvcWaitProcessWideKeyAtomic(ARegisters Registers)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
long MutexAddress = (long)Registers.X0;
|
|
|
|
long CondVarAddress = (long)Registers.X1;
|
|
|
|
int ThreadHandle = (int)Registers.X2;
|
|
|
|
long Timeout = (long)Registers.X3;
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
HThread Thread = Ns.Os.Handles.GetData<HThread>(ThreadHandle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
if (Ns.Os.Mutexes.TryGetValue(MutexAddress, out Mutex M))
|
|
|
|
{
|
|
|
|
M.GiveUpLock(ThreadHandle);
|
|
|
|
}
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
CondVar Cv = new CondVar(Process, CondVarAddress, Timeout);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
Cv = Ns.Os.CondVars.GetOrAdd(CondVarAddress, Cv);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
Cv.WaitForSignal(Thread);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
M = new Mutex(Process, MutexAddress, ThreadHandle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
M = Ns.Os.Mutexes.GetOrAdd(MutexAddress, M);
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
M.WaitForLock(Thread, ThreadHandle);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Registers.X0 = (int)SvcResult.Success;
|
|
|
|
}
|
|
|
|
|
2018-02-14 03:43:08 +01:00
|
|
|
private void SvcSignalProcessWideKey(ARegisters Registers)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
long CondVarAddress = (long)Registers.X0;
|
|
|
|
int Count = (int)Registers.X1;
|
|
|
|
|
|
|
|
if (Ns.Os.CondVars.TryGetValue(CondVarAddress, out CondVar Cv))
|
|
|
|
{
|
|
|
|
Cv.SetSignal(Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
Registers.X0 = (int)SvcResult.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|