1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-10 20:06:40 +00:00
Ryujinx/ChocolArm64/AThread.cs

72 lines
1.6 KiB
C#
Raw Normal View History

2018-02-04 23:08:20 +00:00
using ChocolArm64.Memory;
using ChocolArm64.State;
using System;
using System.Threading;
namespace ChocolArm64
{
public class AThread
2018-02-04 23:08:20 +00:00
{
2018-02-19 19:37:13 +00:00
public AThreadState ThreadState { get; private set; }
public AMemory Memory { get; private set; }
2018-02-04 23:08:20 +00:00
public long EntryPoint { get; private set; }
2018-02-04 23:08:20 +00:00
private ATranslator Translator;
private ThreadPriority Priority;
private Thread Work;
2018-02-04 23:08:20 +00:00
public event EventHandler WorkFinished;
2018-02-18 19:28:07 +00:00
public int ThreadId => ThreadState.ThreadId;
2018-02-04 23:08:20 +00:00
public bool IsAlive => Work.IsAlive;
private bool IsExecuting;
private object ExecuteLock;
2018-02-04 23:08:20 +00:00
public AThread(AMemory Memory, ThreadPriority Priority, long EntryPoint)
2018-02-04 23:08:20 +00:00
{
this.Memory = Memory;
this.Priority = Priority;
this.EntryPoint = EntryPoint;
2018-02-04 23:08:20 +00:00
2018-02-18 19:28:07 +00:00
ThreadState = new AThreadState();
Translator = new ATranslator(this);
ExecuteLock = new object();
2018-02-04 23:08:20 +00:00
}
public void StopExecution() => Translator.StopExecution();
public bool Execute()
2018-02-04 23:08:20 +00:00
{
lock (ExecuteLock)
{
if (IsExecuting)
{
return false;
}
IsExecuting = true;
}
2018-02-04 23:08:20 +00:00
Work = new Thread(delegate()
{
Translator.ExecuteSubroutine(EntryPoint);
Memory.RemoveMonitor(ThreadId);
WorkFinished?.Invoke(this, EventArgs.Empty);
});
Work.Priority = Priority;
2018-02-04 23:08:20 +00:00
Work.Start();
return true;
2018-02-04 23:08:20 +00:00
}
}
}