| 87 | } |
| 88 | |
| 89 | hx::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 | |
| 112 | int hx::thread::Thread_obj::id() |
| 113 | { |