1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-14 06:46:39 +00:00
Ryujinx/ChocolArm64/CpuThread.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 CpuThread
2018-02-04 23:08:20 +00:00
{
public CpuThreadState ThreadState { get; private set; }
public MemoryManager Memory { get; private set; }
2018-02-04 23:08:20 +00:00
private Translator _translator;
public Thread Work;
2018-02-04 23:08:20 +00:00
public event EventHandler WorkFinished;
private int _isExecuting;
public CpuThread(Translator translator, MemoryManager memory, long entrypoint)
2018-02-04 23:08:20 +00:00
{
_translator = translator;
Memory = memory;
2018-02-04 23:08:20 +00:00
ThreadState = new CpuThreadState();
2018-02-04 23:08:20 +00:00
ThreadState.ExecutionMode = ExecutionMode.AArch64;
ThreadState.Running = true;
Work = new Thread(delegate()
{
translator.ExecuteSubroutine(this, entrypoint);
memory.RemoveMonitor(ThreadState.Core);
WorkFinished?.Invoke(this, EventArgs.Empty);
});
}
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.Start();
return true;
2018-02-04 23:08:20 +00:00
}
public void StopExecution()
{
ThreadState.Running = false;
}
public void RequestInterrupt()
{
ThreadState.RequestInterrupt();
}
public bool IsCurrentThread()
{
return Thread.CurrentThread == Work;
}
2018-02-04 23:08:20 +00:00
}
}