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

@ -126,6 +126,11 @@ private class SocketOutput extends haxe.io.Output {
__s = new PSocket();
}
function __rebuildIoStreams():Void {
input = new SocketInput(__s);
output = new SocketOutput(__s);
}
public function close():Void {
__s.close();
}

View File

@ -0,0 +1,34 @@
package sys.thread;
@:coreApi
class Condition {
final cond:python.lib.threading.Condition;
public function new():Void {
this.cond = new python.lib.threading.Condition();
}
public function acquire():Void {
cond.acquire();
}
public function tryAcquire():Bool {
return cond.acquire(false);
}
public function release():Void {
cond.release();
}
public function wait():Void {
cond.wait();
}
public function signal():Void {
cond.notify();
}
public function broadcast():Void {
cond.notify_all();
}
}

View File

@ -22,15 +22,17 @@
package sys.thread;
import python.lib.threading.Condition;
using python.internal.UBuiltins;
class Deque<T> {
var deque:NativeDeque<T>;
var lock:NativeCondition;
var lock:Condition;
public function new() {
deque = new NativeDeque<T>();
lock = new NativeCondition();
lock = new Condition();
}
public function add(i:T) {
@ -63,21 +65,9 @@ class Deque<T> {
@:pythonImport("collections", "deque")
@:native("deque")
extern class NativeDeque<T> {
private extern class NativeDeque<T> {
function new();
function append(x:T):Void;
function appendleft(x:T):Void;
function popleft():T;
}
@:pythonImport("threading", "Condition")
@:native("Condition")
private extern class NativeCondition {
function new(?lock:Dynamic);
function acquire(blocking:Bool = true, timeout:Float = -1):Bool;
function release():Void;
function wait(?timeout:Float):Bool;
function wait_for(predicate:()->Bool, ?timeout:Float):Bool;
function notify(n:Int = 1):Void;
function notify_all():Void;
}

View File

@ -22,12 +22,14 @@
package sys.thread;
import python.lib.threading.Semaphore;
@:coreApi
class Lock {
final semaphore:NativeSemaphore;
final semaphore:Semaphore;
public inline function new() {
semaphore = new NativeSemaphore(0);
semaphore = new Semaphore(0);
}
public inline function wait(?timeout:Float):Bool {
@ -38,11 +40,3 @@ class Lock {
semaphore.release();
}
}
@:pythonImport("threading", "Semaphore")
@:native("Lock")
private extern class NativeSemaphore {
function new(value:Int);
function acquire(blocking:Bool = true, ?timeout:Float):Bool;
function release():Void;
}

View File

@ -22,12 +22,14 @@
package sys.thread;
import python.lib.threading.RLock;
@:coreApi
class Mutex {
final lock:NativeRLock;
final lock:RLock;
inline public function new():Void {
lock = new NativeRLock();
lock = new RLock();
}
inline public function acquire():Void {
@ -42,10 +44,3 @@ class Mutex {
lock.release();
}
}
@:pythonImport("threading", "RLock")
private extern class NativeRLock {
function new():Void;
function acquire(blocking:Bool):Bool;
function release():Void;
}

View File

@ -0,0 +1,24 @@
package sys.thread;
import python.lib.threading.Semaphore as NativeSemaphore;
@:coreApi
class Semaphore {
final semaphore:NativeSemaphore;
public function new(value:Int):Void {
this.semaphore = new NativeSemaphore(value);
}
public function acquire():Void {
semaphore.acquire();
}
public function tryAcquire(?timeout:Float):Bool {
return timeout == null ? semaphore.acquire(false) : semaphore.acquire(true, timeout);
}
public function release():Void {
semaphore.release();
}
}

View File

@ -22,6 +22,9 @@
package sys.thread;
import python.lib.threading.Thread as NativeThread;
import python.lib.Threading;
import haxe.ds.ObjectMap;
private typedef ThreadImpl = HxThread;
@ -33,8 +36,8 @@ abstract Thread(ThreadImpl) from ThreadImpl {
return HxThread.current();
}
public static inline function create(callb:Void->Void):Thread {
return HxThread.create(callb, false);
public static inline function create(job:Void->Void):Thread {
return HxThread.create(job, false);
}
public static inline function runWithEventLoop(job:()->Void):Void {
@ -78,7 +81,7 @@ private class HxThread {
static function __init__() {
threads = new ObjectMap();
threadsMutex = new Mutex();
mainThread = new HxThread(PyThreadingAPI.current_thread());
mainThread = new HxThread(Threading.current_thread());
mainThread.events = new EventLoop();
}
@ -92,8 +95,8 @@ private class HxThread {
public static function current():HxThread {
threadsMutex.acquire();
var ct = PyThreadingAPI.current_thread();
if (ct == PyThreadingAPI.main_thread()) {
var ct = Threading.current_thread();
if (ct == Threading.main_thread()) {
threadsMutex.release();
return mainThread;
}
@ -121,7 +124,7 @@ private class HxThread {
}
dropThread(nt);
}
nt = new NativeThread(null, wrappedCallB);
nt = new NativeThread({target:wrappedCallB});
t = new HxThread(nt);
if(withEventLoop)
t.events = new EventLoop();
@ -159,17 +162,3 @@ private class HxThread {
return current().messages.pop(block);
}
}
@:pythonImport("threading", "Thread")
@:native("Thread")
private extern class NativeThread {
function new(group:Dynamic, target:Void->Void);
function start():Void;
}
@:pythonImport("threading")
@:native("threading")
private extern class PyThreadingAPI {
static function current_thread():NativeThread;
static function main_thread():NativeThread;
}