| 37 | std::atomic_int nextThreadnumber(0); |
| 38 | |
| 39 | void run(hx::thread::ThreadImpl thread, hx::thread::Thread_obj::CreateFunction job, hx::thread::CountingSemaphore semaphore) |
| 40 | { |
| 41 | // info[1] will the the "top of stack" - values under this |
| 42 | // (ie info[0] and other stack values) will be in the GC conservative range |
| 43 | // |
| 44 | // I'm assuming the array of two elements is some trick to ensure it's on the stack. |
| 45 | // Maybe we could use OS specific functions to get the stack range? |
| 46 | |
| 47 | auto root = new hx::Object* { thread.GetPtr() }; |
| 48 | |
| 49 | hx::GCAddRoot(root); |
| 50 | |
| 51 | tls.set(root); |
| 52 | |
| 53 | auto info = std::array<hx::thread::ThreadImpl_obj*, 2>{ thread.GetPtr(), nullptr }; |
| 54 | |
| 55 | hx::SetTopOfStack(reinterpret_cast<int*>(&info[1]), true); |
| 56 | |
| 57 | // Release the creation function |
| 58 | semaphore->release(); |
| 59 | |
| 60 | job(); |
| 61 | |
| 62 | hx::UnregisterCurrentThread(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | hx::thread::Thread hx::thread::Thread_obj::create(CreateFunction job) |
no test coverage detected