Allow more than one process, free resources on process dispose, implement SvcExitThread

This commit is contained in:
gdkchan 2018-03-12 01:04:52 -03:00
parent 3aaa4717b6
commit 7a27990faa
46 changed files with 926 additions and 598 deletions

View file

@ -14,43 +14,30 @@ namespace ChocolArm64
private ATranslator Translator;
private ThreadPriority Priority;
private Thread Work;
public event EventHandler WorkFinished;
public int ThreadId => ThreadState.ThreadId;
public bool IsAlive => Work.IsAlive;
private int IsExecuting;
private bool IsExecuting;
private object ExecuteLock;
public AThread(ATranslator Translator, AMemory Memory, ThreadPriority Priority, long EntryPoint)
public AThread(ATranslator Translator, AMemory Memory, long EntryPoint)
{
this.Translator = Translator;
this.Memory = Memory;
this.Priority = Priority;
this.EntryPoint = EntryPoint;
ThreadState = new AThreadState();
ExecuteLock = new object();
}
public void StopExecution() => Translator.StopExecution();
ThreadState.Running = true;
}
public bool Execute()
{
lock (ExecuteLock)
if (Interlocked.Exchange(ref IsExecuting, 1) == 1)
{
if (IsExecuting)
{
return false;
}
IsExecuting = true;
return false;
}
Work = new Thread(delegate()
@ -62,11 +49,11 @@ namespace ChocolArm64
WorkFinished?.Invoke(this, EventArgs.Empty);
});
Work.Priority = Priority;
Work.Start();
return true;
}
public void StopExecution() => ThreadState.Running = false;
}
}