1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-01 00:42:03 +00:00
Ryujinx/Ryujinx.HLE/HOS/Kernel/KConditionVariable.cs

71 lines
2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Threading;
namespace Ryujinx.HLE.HOS.Kernel
{
static class KConditionVariable
{
2018-12-01 20:01:59 +00:00
public static void Wait(Horizon system, LinkedList<KThread> threadList, object mutex, long timeout)
{
2018-12-01 20:01:59 +00:00
KThread currentThread = system.Scheduler.GetCurrentThread();
2018-12-01 20:01:59 +00:00
system.CriticalSection.Enter();
2018-12-01 20:01:59 +00:00
Monitor.Exit(mutex);
2018-12-01 20:01:59 +00:00
currentThread.Withholder = threadList;
2018-12-01 20:01:59 +00:00
currentThread.Reschedule(ThreadSchedState.Paused);
2018-12-01 20:01:59 +00:00
currentThread.WithholderNode = threadList.AddLast(currentThread);
2018-12-01 20:01:59 +00:00
if (currentThread.ShallBeTerminated ||
currentThread.SchedFlags == ThreadSchedState.TerminationPending)
{
2018-12-01 20:01:59 +00:00
threadList.Remove(currentThread.WithholderNode);
2018-12-01 20:01:59 +00:00
currentThread.Reschedule(ThreadSchedState.Running);
2018-12-01 20:01:59 +00:00
currentThread.Withholder = null;
2018-12-01 20:01:59 +00:00
system.CriticalSection.Leave();
}
else
{
2018-12-01 20:01:59 +00:00
if (timeout > 0)
{
2018-12-01 20:01:59 +00:00
system.TimeManager.ScheduleFutureInvocation(currentThread, timeout);
}
2018-12-01 20:01:59 +00:00
system.CriticalSection.Leave();
2018-12-01 20:01:59 +00:00
if (timeout > 0)
{
2018-12-01 20:01:59 +00:00
system.TimeManager.UnscheduleFutureInvocation(currentThread);
}
}
2018-12-01 20:01:59 +00:00
Monitor.Enter(mutex);
}
2018-12-01 20:01:59 +00:00
public static void NotifyAll(Horizon system, LinkedList<KThread> threadList)
{
2018-12-01 20:01:59 +00:00
system.CriticalSection.Enter();
2018-12-01 20:01:59 +00:00
LinkedListNode<KThread> node = threadList.First;
2018-12-01 20:01:59 +00:00
for (; node != null; node = threadList.First)
{
2018-12-01 20:01:59 +00:00
KThread thread = node.Value;
2018-12-01 20:01:59 +00:00
threadList.Remove(thread.WithholderNode);
2018-12-01 20:01:59 +00:00
thread.Withholder = null;
2018-12-01 20:01:59 +00:00
thread.Reschedule(ThreadSchedState.Running);
}
2018-12-01 20:01:59 +00:00
system.CriticalSection.Leave();
}
}
}