This commit is contained in:
Dante
2026-05-21 23:40:20 -07:00
parent 3e2915dff7
commit 877a69d844
5737 changed files with 29796 additions and 1589684 deletions

View File

@ -50,7 +50,10 @@ private class SocketInput extends haxe.io.Input {
__s.handshake();
var r = @:privateAccess __s.ssl.recv(buf, pos, len);
if (r == -1)
throw haxe.io.Error.Blocked;
if (@:privateAccess __s.isBlocking)
return 0
else
throw haxe.io.Error.Blocked;
else if (r <= 0)
throw new haxe.io.Eof();
return r;
@ -85,7 +88,10 @@ private class SocketOutput extends haxe.io.Output {
__s.handshake();
var r = @:privateAccess __s.ssl.send(buf, pos, len);
if (r == -1)
throw haxe.io.Error.Blocked;
if (@:privateAccess __s.isBlocking)
return 0
else
throw haxe.io.Error.Blocked;
else if (r < 0)
throw new haxe.io.Eof();
return r;

View File

@ -0,0 +1,50 @@
package sys.thread;
#if doc_gen
@:coreApi extern class Condition {
function new():Void;
public function acquire():Void;
public function tryAcquire():Bool;
public function release():Void;
public function wait():Void;
public function signal():Void;
public function broadcast():Void;
}
#else
abstract Condition(hl.Abstract<"hl_condition">) {
public function new():Void {
this = alloc();
}
@:hlNative("std", "condition_acquire")
public function acquire():Void {}
@:hlNative("std", "condition_try_acquire")
public function tryAcquire():Bool {
return false;
}
@:hlNative("std", "condition_release")
public function release():Void {}
@:hlNative("std", "condition_wait")
public function wait():Void {}
@:hlNative("std", "condition_signal")
public function signal():Void {}
@:hlNative("std", "condition_broadcast")
public function broadcast():Void {}
@:hlNative("std", "condition_alloc")
static function alloc():hl.Abstract<"hl_condition"> {
return null;
}
}
#end

View File

@ -0,0 +1,32 @@
package sys.thread;
#if doc_gen
@:coreApi extern class Semaphore {
function new(value:Int):Void;
function acquire():Void;
function tryAcquire(?timeout:Float):Bool;
function release():Void;
}
#else
abstract Semaphore(hl.Abstract<"hl_semaphore">) {
public function new(value:Int):Void {
this = alloc(value);
}
@:hlNative("std", "semaphore_acquire")
public function acquire():Void {}
@:hlNative("std", "semaphore_release")
public function release():Void {}
@:hlNative("std", "semaphore_try_acquire")
public function tryAcquire(?timeout:Float):Bool {
return false;
}
@:hlNative("std", "semaphore_alloc")
static function alloc(value:Int):hl.Abstract<"hl_semaphore"> {
return null;
}
}
#end

View File

@ -51,6 +51,27 @@ abstract Thread(ThreadImpl) from ThreadImpl {
return HaxeThread.current();
}
public function setName( name : String ) {
#if (hl_ver >= version("1.13.0"))
set_name(@:privateAccess this.handle, @:privateAccess name.toUtf8());
#end
}
public function getName() : Null<String> {
#if (hl_ver >= version("1.13.0"))
var name = get_name(@:privateAccess this.handle);
return name == null ? null : @:privateAccess String.fromUTF8(name);
#else
return null;
#end
}
#if (hl_ver >= version("1.13.0"))
@:hlNative("?std", "thread_set_name") static function set_name( t : ThreadHandle, name : hl.Bytes ) {}
@:hlNative("?std", "thread_get_name") static function get_name( t : ThreadHandle ) : hl.Bytes { return null; }
#end
function get_events():EventLoop {
if(this.events == null)
throw new NoEventLoopException();
@ -66,25 +87,24 @@ abstract Thread(ThreadImpl) from ThreadImpl {
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 threads:Array<HaxeThread>;
static var threadsMutex:Mutex;
static var UID = 0;
static function __init__() {
mainThreadHandle = currentHandle();
threadsMutex = new Mutex();
threads = [];
mainThread = new HaxeThread();
mainThread = new HaxeThread(currentHandle());
mainThread.events = new EventLoop();
}
var id = UID++;
public var events(default,null):Null<EventLoop>;
var handle : ThreadHandle;
final messages = new Deque();
static var ids = 0;
var id = ids++;
@:hlNative("std", "thread_create")
static function createHandle(callb:Void->Void):ThreadHandle {
return null;
@ -97,47 +117,49 @@ private class HaxeThread {
static public function current():HaxeThread {
var handle = currentHandle();
if(handle == mainThreadHandle) {
if(handle == mainThread.handle) {
return mainThread;
}
threadsMutex.acquire();
var thread = null;
for(item in threads) {
if(item.handle == handle) {
thread = item.thread;
thread = item;
break;
}
}
if(thread == null) {
thread = new HaxeThread();
threads.push({thread:thread, handle:handle});
thread = new HaxeThread(handle);
threads.push(thread);
}
threadsMutex.release();
return thread;
}
public static function create(callb:()->Void, withEventLoop:Bool):Thread {
var item = {handle:null, thread:new HaxeThread()};
var item = new HaxeThread(null);
threadsMutex.acquire();
threads.push(item);
threadsMutex.release();
if(withEventLoop)
item.thread.events = new EventLoop();
item.events = new EventLoop();
item.handle = createHandle(() -> {
if(item.handle == null) {
item.handle = currentHandle();
}
try {
hl.Api.setErrorHandler(function(_){});
callb();
if(withEventLoop)
item.thread.events.loop();
item.events.loop();
} catch(e) {
hl.Api.setErrorHandler(null);
dropThread(item);
throw e;
hl.Api.rethrow(e);
}
dropThread(item);
});
return item.thread;
return item;
}
public static function runWithEventLoop(job:()->Void):Void {
@ -172,7 +194,9 @@ private class HaxeThread {
return messages.pop(block);
}
public function new() {}
public function new(h) {
handle = h;
}
public function sendMessage(msg:Dynamic) {
messages.add(msg);