|
@@ -34,8 +34,15 @@ private class Thread {
|
|
**/
|
|
**/
|
|
class EntryPoint {
|
|
class EntryPoint {
|
|
#if sys
|
|
#if sys
|
|
- static var sleepLock = new Lock();
|
|
|
|
- static var mutex = new Mutex();
|
|
|
|
|
|
+ static var mutex = new Mutex();
|
|
|
|
+ #if (target.threaded && !cppia)
|
|
|
|
+ static var mainThread:Thread;
|
|
|
|
+ @:keep static function init() {
|
|
|
|
+ mainThread = Thread.current();
|
|
|
|
+ }
|
|
|
|
+ #else
|
|
|
|
+ static var sleepLock = new Lock();
|
|
|
|
+ #end
|
|
#end
|
|
#end
|
|
static var pending = new Array<Void->Void>();
|
|
static var pending = new Array<Void->Void>();
|
|
public static var threadCount(default, null):Int = 0;
|
|
public static var threadCount(default, null):Int = 0;
|
|
@@ -44,17 +51,21 @@ class EntryPoint {
|
|
Wakeup a sleeping `run()`
|
|
Wakeup a sleeping `run()`
|
|
**/
|
|
**/
|
|
public static function wakeup() {
|
|
public static function wakeup() {
|
|
- #if sys
|
|
|
|
|
|
+ #if (sys && !(target.threaded && !cppia))
|
|
sleepLock.release();
|
|
sleepLock.release();
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
|
|
|
|
public static function runInMainThread(f:Void->Void) {
|
|
public static function runInMainThread(f:Void->Void) {
|
|
#if sys
|
|
#if sys
|
|
- mutex.acquire();
|
|
|
|
- pending.push(f);
|
|
|
|
- mutex.release();
|
|
|
|
- wakeup();
|
|
|
|
|
|
+ #if (target.threaded && !cppia)
|
|
|
|
+ mainThread.events.run(f);
|
|
|
|
+ #else
|
|
|
|
+ mutex.acquire();
|
|
|
|
+ pending.push(f);
|
|
|
|
+ mutex.release();
|
|
|
|
+ wakeup();
|
|
|
|
+ #end
|
|
#else
|
|
#else
|
|
pending.push(f);
|
|
pending.push(f);
|
|
#end
|
|
#end
|
|
@@ -65,6 +76,9 @@ class EntryPoint {
|
|
mutex.acquire();
|
|
mutex.acquire();
|
|
threadCount++;
|
|
threadCount++;
|
|
mutex.release();
|
|
mutex.release();
|
|
|
|
+ #if (target.threaded && !cppia)
|
|
|
|
+ mainThread.events.promise();
|
|
|
|
+ #end
|
|
Thread.create(function() {
|
|
Thread.create(function() {
|
|
f();
|
|
f();
|
|
mutex.acquire();
|
|
mutex.acquire();
|
|
@@ -72,6 +86,9 @@ class EntryPoint {
|
|
if (threadCount == 0)
|
|
if (threadCount == 0)
|
|
wakeup();
|
|
wakeup();
|
|
mutex.release();
|
|
mutex.release();
|
|
|
|
+ #if (target.threaded && !cppia)
|
|
|
|
+ mainThread.events.runPromised(() -> {});
|
|
|
|
+ #end
|
|
});
|
|
});
|
|
#else
|
|
#else
|
|
threadCount++;
|
|
threadCount++;
|
|
@@ -83,6 +100,9 @@ class EntryPoint {
|
|
}
|
|
}
|
|
|
|
|
|
static function processEvents():Float {
|
|
static function processEvents():Float {
|
|
|
|
+ #if (target.threaded && !cppia)
|
|
|
|
+ return -1;
|
|
|
|
+ #else
|
|
// flush all pending calls
|
|
// flush all pending calls
|
|
while (true) {
|
|
while (true) {
|
|
#if sys
|
|
#if sys
|
|
@@ -100,6 +120,7 @@ class EntryPoint {
|
|
if (!MainLoop.hasEvents() && threadCount == 0)
|
|
if (!MainLoop.hasEvents() && threadCount == 0)
|
|
return -1;
|
|
return -1;
|
|
return time;
|
|
return time;
|
|
|
|
+ #end
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -131,18 +152,7 @@ class EntryPoint {
|
|
#elseif flash
|
|
#elseif flash
|
|
flash.Lib.current.stage.addEventListener(flash.events.Event.ENTER_FRAME, function(_) processEvents());
|
|
flash.Lib.current.stage.addEventListener(flash.events.Event.ENTER_FRAME, function(_) processEvents());
|
|
#elseif (target.threaded && !cppia)
|
|
#elseif (target.threaded && !cppia)
|
|
- var mainThread = Thread.current();
|
|
|
|
- var handler = null;
|
|
|
|
- function progress() {
|
|
|
|
- if(handler != null) {
|
|
|
|
- mainThread.events.cancel(handler);
|
|
|
|
- }
|
|
|
|
- var nextTick = processEvents();
|
|
|
|
- if (nextTick > 0) {
|
|
|
|
- handler = mainThread.events.repeat(progress, Std.int(nextTick * 1000.0));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- progress();
|
|
|
|
|
|
+ //everything is delegated to sys.thread.EventLoop
|
|
#elseif sys
|
|
#elseif sys
|
|
while (true) {
|
|
while (true) {
|
|
var nextTick = processEvents();
|
|
var nextTick = processEvents();
|