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 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; } }