本文整理汇总了C++中TaskScheduler::CleanUpOldFiber方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskScheduler::CleanUpOldFiber方法的具体用法?C++ TaskScheduler::CleanUpOldFiber怎么用?C++ TaskScheduler::CleanUpOldFiber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskScheduler
的用法示例。
在下文中一共展示了TaskScheduler::CleanUpOldFiber方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FiberStart
void TaskScheduler::FiberStart(intptr_t arg) {
TaskScheduler *taskScheduler = reinterpret_cast<TaskScheduler *>(arg);
while (!taskScheduler->m_quit.load(std::memory_order_acquire)) {
// Clean up from the last fiber to run on this thread
taskScheduler->CleanUpOldFiber();
// Check if any of the waiting tasks are ready
std::size_t waitingFiberIndex = FTL_INVALID_INDEX;
for (std::size_t i = 0; i < taskScheduler->m_fiberPoolSize; ++i) {
// Double lock
if (!taskScheduler->m_waitingFibers[i].load(std::memory_order_relaxed)) {
continue;
}
if (!taskScheduler->m_waitingFibers[i].load(std::memory_order_acquire)) {
continue;
}
// Found a waiting fiber
// Test if it's ready
WaitingBundle *bundle = &taskScheduler->m_waitingBundles[i];
if (bundle->Counter->load(std::memory_order_relaxed) != bundle->TargetValue) {
continue;
}
bool expected = true;
if (std::atomic_compare_exchange_weak_explicit(&taskScheduler->m_waitingFibers[i], &expected, false, std::memory_order_release, std::memory_order_relaxed)) {
waitingFiberIndex = i;
break;
}
}
if (waitingFiberIndex != FTL_INVALID_INDEX) {
// Found a waiting task that is ready to continue
ThreadLocalStorage &tls = taskScheduler->m_tls[taskScheduler->GetCurrentThreadIndex()];
tls.OldFiberIndex = tls.CurrentFiberIndex;
tls.CurrentFiberIndex = waitingFiberIndex;
tls.OldFiberDestination = FiberDestination::ToPool;
// Switch
taskScheduler->m_fibers[tls.OldFiberIndex].SwitchToFiber(&taskScheduler->m_fibers[tls.CurrentFiberIndex]);
// And we're back
} else {
// Get a new task from the queue, and execute it
TaskBundle nextTask;
if (!taskScheduler->GetNextTask(&nextTask)) {
// Spin
} else {
nextTask.TaskToExecute.Function(taskScheduler, nextTask.TaskToExecute.ArgData);
nextTask.Counter->fetch_sub(1);
}
}
}
// Start the quit sequence
// Switch to the thread fibers
ThreadLocalStorage &tls = taskScheduler->m_tls[taskScheduler->GetCurrentThreadIndex()];
taskScheduler->m_fibers[tls.CurrentFiberIndex].SwitchToFiber(&tls.ThreadFiber);
// We should never get here
printf("Error: FiberStart should never return");
}