| 50 | }; |
| 51 | |
| 52 | FTL_THREAD_FUNC_RETURN_TYPE TaskScheduler::ThreadStartFunc(void *const arg) { |
| 53 | auto *const threadArgs = reinterpret_cast<ThreadStartArgs *>(arg); |
| 54 | TaskScheduler *taskScheduler = threadArgs->Scheduler; |
| 55 | unsigned const index = threadArgs->ThreadIndex; |
| 56 | SetCurrentThreadAffinity(index); |
| 57 | // Clean up |
| 58 | delete threadArgs; |
| 59 | |
| 60 | // Spin wait until everything is initialized |
| 61 | while (!taskScheduler->m_initialized.load(std::memory_order_acquire)) { |
| 62 | // Spin |
| 63 | FTL_PAUSE(); |
| 64 | } |
| 65 | |
| 66 | // Execute user thread start callback, if set |
| 67 | const EventCallbacks &callbacks = taskScheduler->m_callbacks; |
| 68 | if (callbacks.OnWorkerThreadStarted != nullptr) { |
| 69 | callbacks.OnWorkerThreadStarted(callbacks.Context, index); |
| 70 | } |
| 71 | |
| 72 | // Get a free fiber to switch to |
| 73 | unsigned const freeFiberIndex = taskScheduler->GetNextFreeFiberIndex(); |
| 74 | |
| 75 | // Initialize tls |
| 76 | taskScheduler->m_tls[index].CurrentFiberIndex = freeFiberIndex; |
| 77 | // Switch |
| 78 | taskScheduler->m_tls[index].ThreadFiber.SwitchToFiber(&taskScheduler->m_fibers[freeFiberIndex]); |
| 79 | |
| 80 | // And we've returned |
| 81 | |
| 82 | // Execute user thread end callback, if set |
| 83 | if (callbacks.OnWorkerThreadEnded != nullptr) { |
| 84 | callbacks.OnWorkerThreadEnded(callbacks.Context, index); |
| 85 | } |
| 86 | |
| 87 | // Cleanup and shutdown |
| 88 | EndCurrentThread(); |
| 89 | FTL_THREAD_FUNC_END; |
| 90 | } |
| 91 | |
| 92 | // This Task is never used directly |
| 93 | // However, a function pointer to it is the signal that the task is a Ready fiber, not a "real" task |
nothing calls this directly
no test coverage detected