ryujinx/Ryujinx/OsHle/Svc/SvcThreadSync.cs

79 lines
2.3 KiB
C#
Raw Normal View History

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