0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-25 02:05:47 +00:00
Ryujinx/ChocolArm64/AThread.cs

69 lines
1.5 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
private long EntryPoint;
2018-02-04 23:08:20 +00:00
private ATranslator Translator;
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
private int IsExecuting;
public AThread(ATranslator Translator, AMemory Memory, long EntryPoint)
2018-02-04 23:08:20 +00:00
{
this.Translator = Translator;
2018-02-04 23:08:20 +00:00
this.Memory = Memory;
this.EntryPoint = EntryPoint;
2018-02-04 23:08:20 +00:00
2018-02-18 19:28:07 +00:00
ThreadState = new AThreadState();
2018-02-04 23:08:20 +00:00
ThreadState.ExecutionMode = AExecutionMode.AArch64;
ThreadState.Running = true;
}
2018-02-04 23:08:20 +00:00
public bool Execute()
2018-02-04 23:08:20 +00:00
{
if (Interlocked.Exchange(ref IsExecuting, 1) == 1)
{
return false;
}
2018-02-04 23:08:20 +00:00
Work = new Thread(delegate()
{
Translator.ExecuteSubroutine(this, EntryPoint);
2018-02-04 23:08:20 +00:00
Memory.RemoveMonitor(ThreadState);
2018-02-04 23:08:20 +00:00
WorkFinished?.Invoke(this, EventArgs.Empty);
});
Work.Start();
return true;
2018-02-04 23:08:20 +00:00
}
public void StopExecution()
{
ThreadState.Running = false;
}
public bool IsCurrentThread()
{
return Thread.CurrentThread == Work;
}
2018-02-04 23:08:20 +00:00
}
}