From fe56a1ed8fd6b90e9fd42e1dd70c6c218fb511ae Mon Sep 17 00:00:00 2001 From: Aidan Lee Date: Sun, 26 Apr 2026 15:23:20 +0100 Subject: [PATCH 1/2] Typed thread and tls --- std/cpp/_std/sys/thread/ThreadImpl.hx | 23 ++++++++++++++--------- std/cpp/_std/sys/thread/Tls.hx | 24 ++++++++++++++---------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/std/cpp/_std/sys/thread/ThreadImpl.hx b/std/cpp/_std/sys/thread/ThreadImpl.hx index d76ad34a32d..5ec2d49931a 100644 --- a/std/cpp/_std/sys/thread/ThreadImpl.hx +++ b/std/cpp/_std/sys/thread/ThreadImpl.hx @@ -22,27 +22,32 @@ package sys.thread; -@:callable -@:coreType -private abstract NativeThreadHandle {} - -private typedef ThreadHandle = NativeThreadHandle; +@:include("hx/thread/Thread.hpp") +@:cpp.ManagedType({ namespace : [ "hx", "thread" ], type : "Thread", flags : [ StandardNaming ] }) +private extern class NativeThread { + static function create(job:()->Void):NativeThread; + static function current():NativeThread; + + function getName():String; + function setName(name:String):Void; +} -abstract ThreadImpl(ThreadHandle) { +abstract ThreadImpl(NativeThread) { public static #if !scriptable inline #end function current():ThreadImpl { - return untyped __global__.__hxcpp_thread_current(); + return cast NativeThread.current(); } public static #if !scriptable inline #end function create(job:Void->Void):ThreadImpl { - return untyped __global__.__hxcpp_thread_create(job); + return cast NativeThread.create(job); } public static function setName( t : ThreadImpl, name : String ) { + (cast t : NativeThread).setName(name); } public static function getName( t : ThreadImpl ) { - return null; + return (cast t : NativeThread).getName(); } } diff --git a/std/cpp/_std/sys/thread/Tls.hx b/std/cpp/_std/sys/thread/Tls.hx index edfc3f56522..5e904773467 100644 --- a/std/cpp/_std/sys/thread/Tls.hx +++ b/std/cpp/_std/sys/thread/Tls.hx @@ -22,28 +22,32 @@ package sys.thread; +@:include("hx/thread/ThreadLocal.hpp") +@:cpp.ManagedType({ namespace : [ "hx", "thread" ], flags : [ StandardNaming ] }) +private extern class ThreadLocal { + function new():Void; + + function get():Dynamic; + function set(obj:Dynamic):Void; +} + @:coreApi class Tls { - static var sFreeSlot:Int; - - var mTLSID:Int; + final tls:ThreadLocal; public var value(get, set):Null; public function new() { - mTLSID = sFreeSlot++; + tls = new ThreadLocal(); } function get_value():Null { - return untyped __global__.__hxcpp_tls_get(mTLSID); + return tls.get(); } function set_value(v:Null):Null { - untyped __global__.__hxcpp_tls_set(mTLSID, v); - return v; - } + tls.set(v); - static function __init__ ():Void { - sFreeSlot = 0; + return v; } } From ea12f1b897e76dd65a52ebe628fda14e55605cad Mon Sep 17 00:00:00 2001 From: Aidan Lee Date: Sun, 26 Apr 2026 19:44:09 +0100 Subject: [PATCH 2/2] Add scratch class extern --- std/cpp/Scratch.hx | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 std/cpp/Scratch.hx diff --git a/std/cpp/Scratch.hx b/std/cpp/Scratch.hx new file mode 100644 index 00000000000..b4e2b80b5ed --- /dev/null +++ b/std/cpp/Scratch.hx @@ -0,0 +1,10 @@ +package cpp; + +@:include("hx/thread/Scratch.hpp") +@:semantics(value) +@:cpp.ValueType({ namespace : [ "hx", "thread" ], flags : [ StackOnly ] }) +private extern class Scratch { + final view : cpp.marshal.View; + + static function alloc(bytes:Int):Scratch; +} \ No newline at end of file