MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / current

Method current

src/hx/thread/ThreadImpl.cpp:89–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89hx::thread::Thread hx::thread::Thread_obj::current()
90{
91 auto info = tls.get();
92 if (nullptr == info)
93 {
94 // Threads created from Haxe have the TLS set, and the GC sets the TLS for the main thread.
95 // So, if the TLS is null then we are in a attached foreign thread, which will just get assigned the next Id.
96 //
97 // The C++ std has no way of getting the native handle of the current thread, so we need to use OS specific
98 // apis to get that so we can get and set thread names.
99 info = new ThreadImpl_obj(nextThreadnumber++);
100
101 auto root = new hx::Object* { info };
102
103 hx::GCSetFinalizer(info, ThreadImpl_obj::finalise);
104 hx::GCAddRoot(root);
105
106 tls.set(root);
107 }
108
109 return Thread{ info };
110}
111
112int hx::thread::Thread_obj::id()
113{

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected