Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions std/cpp/Scratch.hx
Original file line number Diff line number Diff line change
@@ -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<cpp.UInt8>;

static function alloc(bytes:Int):Scratch;
}
23 changes: 14 additions & 9 deletions std/cpp/_std/sys/thread/ThreadImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
24 changes: 14 additions & 10 deletions std/cpp/_std/sys/thread/Tls.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
static var sFreeSlot:Int;

var mTLSID:Int;
final tls:ThreadLocal;

public var value(get, set):Null<T>;

public function new() {
mTLSID = sFreeSlot++;
tls = new ThreadLocal();
}

function get_value():Null<T> {
return untyped __global__.__hxcpp_tls_get(mTLSID);
return tls.get();
}

function set_value(v:Null<T>):Null<T> {
untyped __global__.__hxcpp_tls_set(mTLSID, v);
return v;
}
tls.set(v);

static function __init__ ():Void {
sFreeSlot = 0;
return v;
}
}
Loading