you can stop the turtle thread now
This commit is contained in:
parent
a46760e587
commit
21387cd8e7
@ -97,6 +97,7 @@ class KernelEvents {
|
|||||||
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
||||||
|
|
||||||
private static var stopLoop:Bool = false;
|
private static var stopLoop:Bool = false;
|
||||||
|
private static var turtleCoroutine:Coroutine<Dynamic>;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
@ -144,15 +145,19 @@ class KernelEvents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function turtleLoop() {
|
@:allow(kernel.turtle.TurtleMutex)
|
||||||
var turtleCoroutine = Coroutine.create(runTurtleLoop);
|
private static function startTurtleCoroutine() {
|
||||||
|
turtleCoroutine = Coroutine.create(runTurtleLoop);
|
||||||
Coroutine.resume(turtleCoroutine);
|
Coroutine.resume(turtleCoroutine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function turtleLoop() {
|
||||||
|
startTurtleCoroutine();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var eventData = pullEvents();
|
var eventData = pullEvents();
|
||||||
|
|
||||||
if (eventData[1] == "turtle_response" || eventData[1] == "tthread") {
|
if (eventData[1] == "turtle_response" || eventData[1] == "tthread") {
|
||||||
Log.debug('Resuming turtle thread');
|
|
||||||
var result = Coroutine.resume(turtleCoroutine, TableTools.unpack(eventData));
|
var result = Coroutine.resume(turtleCoroutine, TableTools.unpack(eventData));
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
@ -170,7 +175,9 @@ class KernelEvents {
|
|||||||
|
|
||||||
private static function runTurtleLoop() {
|
private static function runTurtleLoop() {
|
||||||
while (!stopLoop) {
|
while (!stopLoop) {
|
||||||
Coroutine.yield();
|
if ((TableTools.pack(Coroutine.yield()))[1] != "tthread")
|
||||||
|
continue;
|
||||||
|
|
||||||
if (stopLoop)
|
if (stopLoop)
|
||||||
continue;
|
continue;
|
||||||
TurtleMutex.runThreadFunc();
|
TurtleMutex.runThreadFunc();
|
||||||
|
@ -43,4 +43,9 @@ class TurtleMutex {
|
|||||||
threadFunc = func;
|
threadFunc = func;
|
||||||
OS.queueEvent("tthread");
|
OS.queueEvent("tthread");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function stopTurtleThread() {
|
||||||
|
threadFunc = null;
|
||||||
|
KernelEvents.startTurtleCoroutine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user