2018-09-19 01:36:43 +02:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
{
|
|
|
|
class HleCoreManager
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
private class PausableThread
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
public ManualResetEvent Event { get; private set; }
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
public bool IsExiting { get; set; }
|
|
|
|
|
|
|
|
public PausableThread()
|
|
|
|
{
|
|
|
|
Event = new ManualResetEvent(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private ConcurrentDictionary<Thread, PausableThread> Threads;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
public HleCoreManager()
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Threads = new ConcurrentDictionary<Thread, PausableThread>();
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public void Set(Thread Thread)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
GetThread(Thread).Event.Set();
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public void Reset(Thread Thread)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
GetThread(Thread).Event.Reset();
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public void Wait(Thread Thread)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
PausableThread PausableThread = GetThread(Thread);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (!PausableThread.IsExiting)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
PausableThread.Event.WaitOne();
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public void Exit(Thread Thread)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
GetThread(Thread).IsExiting = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private PausableThread GetThread(Thread Thread)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return Threads.GetOrAdd(Thread, (Key) => new PausableThread());
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public void RemoveThread(Thread Thread)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Threads.TryRemove(Thread, out PausableThread PausableThread))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
PausableThread.Event.Set();
|
|
|
|
PausableThread.Event.Dispose();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|