forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
52
Kha/Tools/macos/std/hl/_std/sys/thread/Deque.hx
Normal file
52
Kha/Tools/macos/std/hl/_std/sys/thread/Deque.hx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
#if doc_gen
|
||||
@:coreApi extern class Deque<T> {
|
||||
function new():Void;
|
||||
function add(i:T):Void;
|
||||
function push(i:T):Void;
|
||||
function pop(block:Bool):Null<T>;
|
||||
}
|
||||
#else
|
||||
|
||||
@:hlNative("std", "deque_")
|
||||
abstract Deque<T>(hl.Abstract<"hl_deque">) {
|
||||
public function new() {
|
||||
this = alloc();
|
||||
}
|
||||
|
||||
public function add(i:T) {}
|
||||
|
||||
public function push(i:T) {}
|
||||
|
||||
public function pop(block:Bool):Null<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function alloc() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#end
|
87
Kha/Tools/macos/std/hl/_std/sys/thread/Lock.hx
Normal file
87
Kha/Tools/macos/std/hl/_std/sys/thread/Lock.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
|
||||
#if (hl_ver >= version("1.11.0"))
|
||||
|
||||
typedef LockHandle = hl.Abstract<"hl_lock">;
|
||||
|
||||
@:coreApi
|
||||
@:hlNative("std")
|
||||
class Lock {
|
||||
var handle : LockHandle;
|
||||
|
||||
public function new() {
|
||||
handle = lock_create();
|
||||
}
|
||||
|
||||
public function wait( ?timeout : Float ) : Bool {
|
||||
return lock_wait(handle, timeout);
|
||||
}
|
||||
|
||||
public function release( ) : Void {
|
||||
lock_release(handle);
|
||||
}
|
||||
|
||||
static function lock_wait( handle : LockHandle, ?timeout : Float ) : Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function lock_release( handle : LockHandle ) : Void { }
|
||||
|
||||
static function lock_create( ) : LockHandle {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@:coreApi
|
||||
class Lock {
|
||||
var deque:sys.thread.Deque<Bool>;
|
||||
|
||||
public function new():Void {
|
||||
deque = new Deque<Null<Bool>>();
|
||||
}
|
||||
|
||||
public function wait(?timeout:Float):Bool {
|
||||
if (timeout == null) {
|
||||
deque.pop(true);
|
||||
return true;
|
||||
}
|
||||
var targetTime = haxe.Timer.stamp() + timeout;
|
||||
do {
|
||||
if (deque.pop(false) != null) {
|
||||
return true;
|
||||
}
|
||||
} while (haxe.Timer.stamp() < targetTime);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function release():Void {
|
||||
deque.push(true);
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
52
Kha/Tools/macos/std/hl/_std/sys/thread/Mutex.hx
Normal file
52
Kha/Tools/macos/std/hl/_std/sys/thread/Mutex.hx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
#if doc_gen
|
||||
@:coreApi
|
||||
extern class Mutex {
|
||||
function new():Void;
|
||||
function acquire():Void;
|
||||
function tryAcquire():Bool;
|
||||
function release():Void;
|
||||
}
|
||||
#else
|
||||
|
||||
abstract Mutex(hl.Abstract<"hl_mutex">) {
|
||||
public function new() {
|
||||
this = alloc(true);
|
||||
}
|
||||
|
||||
@:hlNative("std", "mutex_acquire") public function acquire() {}
|
||||
|
||||
@:hlNative("std", "mutex_try_acquire") public function tryAcquire():Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "mutex_release") public function release() {}
|
||||
|
||||
@:hlNative("std", "mutex_alloc") public static function alloc(b:Bool) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#end
|
180
Kha/Tools/macos/std/hl/_std/sys/thread/Thread.hx
Normal file
180
Kha/Tools/macos/std/hl/_std/sys/thread/Thread.hx
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
private typedef ThreadImpl = HaxeThread;
|
||||
|
||||
abstract Thread(ThreadImpl) from ThreadImpl {
|
||||
public var events(get,never):EventLoop;
|
||||
|
||||
public inline function sendMessage(msg:Dynamic) {
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
|
||||
public static inline function readMessage(block = true):Dynamic {
|
||||
return HaxeThread.current().readMessage(block);
|
||||
}
|
||||
|
||||
public static inline function create(job:()->Void):Thread {
|
||||
return HaxeThread.create(job, false);
|
||||
}
|
||||
|
||||
public static inline function runWithEventLoop(job:()->Void):Void {
|
||||
HaxeThread.runWithEventLoop(job);
|
||||
}
|
||||
|
||||
public static inline function createWithEventLoop(job:()->Void):Thread {
|
||||
return HaxeThread.create(job, true);
|
||||
}
|
||||
|
||||
public static function current():Thread {
|
||||
return HaxeThread.current();
|
||||
}
|
||||
|
||||
function get_events():EventLoop {
|
||||
if(this.events == null)
|
||||
throw new NoEventLoopException();
|
||||
return this.events;
|
||||
}
|
||||
|
||||
@:keep
|
||||
static public function processEvents() {
|
||||
HaxeThread.current().events.loop();
|
||||
}
|
||||
}
|
||||
|
||||
private typedef ThreadHandle = hl.Abstract<"hl_thread">;
|
||||
|
||||
private class HaxeThread {
|
||||
static var mainThreadHandle:ThreadHandle;
|
||||
static var mainThread:HaxeThread;
|
||||
static var threads:Array<{thread:HaxeThread, handle:ThreadHandle}>;
|
||||
static var threadsMutex:Mutex;
|
||||
|
||||
static function __init__() {
|
||||
mainThreadHandle = currentHandle();
|
||||
threadsMutex = new Mutex();
|
||||
threads = [];
|
||||
mainThread = new HaxeThread();
|
||||
mainThread.events = new EventLoop();
|
||||
}
|
||||
|
||||
public var events(default,null):Null<EventLoop>;
|
||||
final messages = new Deque();
|
||||
|
||||
static var ids = 0;
|
||||
var id = ids++;
|
||||
|
||||
@:hlNative("std", "thread_create")
|
||||
static function createHandle(callb:Void->Void):ThreadHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "thread_current")
|
||||
static function currentHandle():ThreadHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public function current():HaxeThread {
|
||||
var handle = currentHandle();
|
||||
if(handle == mainThreadHandle) {
|
||||
return mainThread;
|
||||
}
|
||||
threadsMutex.acquire();
|
||||
var thread = null;
|
||||
for(item in threads) {
|
||||
if(item.handle == handle) {
|
||||
thread = item.thread;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(thread == null) {
|
||||
thread = new HaxeThread();
|
||||
threads.push({thread:thread, handle:handle});
|
||||
}
|
||||
threadsMutex.release();
|
||||
return thread;
|
||||
}
|
||||
|
||||
public static function create(callb:()->Void, withEventLoop:Bool):Thread {
|
||||
var item = {handle:null, thread:new HaxeThread()};
|
||||
threadsMutex.acquire();
|
||||
threads.push(item);
|
||||
threadsMutex.release();
|
||||
if(withEventLoop)
|
||||
item.thread.events = new EventLoop();
|
||||
item.handle = createHandle(() -> {
|
||||
if(item.handle == null) {
|
||||
item.handle = currentHandle();
|
||||
}
|
||||
try {
|
||||
callb();
|
||||
if(withEventLoop)
|
||||
item.thread.events.loop();
|
||||
} catch(e) {
|
||||
dropThread(item);
|
||||
throw e;
|
||||
}
|
||||
dropThread(item);
|
||||
});
|
||||
return item.thread;
|
||||
}
|
||||
|
||||
public static function runWithEventLoop(job:()->Void):Void {
|
||||
var thread = current();
|
||||
if(thread.events == null) {
|
||||
thread.events = new EventLoop();
|
||||
try {
|
||||
job();
|
||||
thread.events.loop();
|
||||
thread.events = null;
|
||||
} catch(e) {
|
||||
thread.events = null;
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
job();
|
||||
}
|
||||
}
|
||||
|
||||
static function dropThread(deleteItem) {
|
||||
threadsMutex.acquire();
|
||||
for(i => item in threads) {
|
||||
if(item == deleteItem) {
|
||||
threads.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
threadsMutex.release();
|
||||
}
|
||||
|
||||
public function readMessage(block:Bool):Dynamic {
|
||||
return messages.pop(block);
|
||||
}
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function sendMessage(msg:Dynamic) {
|
||||
messages.add(msg);
|
||||
}
|
||||
}
|
58
Kha/Tools/macos/std/hl/_std/sys/thread/Tls.hx
Normal file
58
Kha/Tools/macos/std/hl/_std/sys/thread/Tls.hx
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
#if doc_gen
|
||||
@:coreApi
|
||||
extern class Tls<T> {
|
||||
var value(get, set):T;
|
||||
function new():Void;
|
||||
}
|
||||
#else
|
||||
|
||||
@:hlNative("std")
|
||||
abstract Tls<T>(hl.Abstract<"hl_tls">) {
|
||||
public var value(get, set):T;
|
||||
|
||||
public function new() {
|
||||
this = tls_alloc(true);
|
||||
}
|
||||
|
||||
function get_value():T {
|
||||
return tls_get(this);
|
||||
}
|
||||
|
||||
function set_value(v:T) {
|
||||
tls_set(this, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static function tls_alloc(gcValue:Bool)
|
||||
return null;
|
||||
|
||||
static function tls_get(t):Dynamic
|
||||
return null;
|
||||
|
||||
static function tls_set(t, v:Dynamic) {}
|
||||
}
|
||||
#end
|
Reference in New Issue
Block a user