本文整理汇总了C++中TaskPool::threadWaiting方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskPool::threadWaiting方法的具体用法?C++ TaskPool::threadWaiting怎么用?C++ TaskPool::threadWaiting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskPool
的用法示例。
在下文中一共展示了TaskPool::threadWaiting方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parallel_for
void parallel_for(TaskPool& pool,
const DELEGATE_CBK<void, const Task&, U32, U32>& cbk,
U32 count,
U32 partitionSize,
TaskPriority priority,
bool noWait,
bool useCurrentThread)
{
if (count > 0) {
const U32 crtPartitionSize = std::min(partitionSize, count);
const U32 partitionCount = count / crtPartitionSize;
const U32 remainder = count % crtPartitionSize;
U32 adjustedCount = partitionCount;
if (useCurrentThread) {
adjustedCount -= 1;
}
std::atomic_uint jobCount = adjustedCount + (remainder > 0 ? 1 : 0);
for (U32 i = 0; i < adjustedCount; ++i) {
const U32 start = i * crtPartitionSize;
const U32 end = start + crtPartitionSize;
CreateTask(pool,
nullptr,
[&cbk, &jobCount, start, end](const Task& parentTask) {
cbk(parentTask, start, end);
jobCount.fetch_sub(1);
}).startTask(priority);
}
if (remainder > 0) {
CreateTask(pool,
nullptr,
[&cbk, &jobCount, count, remainder](const Task& parentTask) {
cbk(parentTask, count - remainder, count);
jobCount.fetch_sub(1);
}).startTask(priority);
}
if (useCurrentThread) {
TaskHandle threadTask = CreateTask(pool, [](const Task& parentTask) {ACKNOWLEDGE_UNUSED(parentTask); });
const U32 start = adjustedCount * crtPartitionSize;
const U32 end = start + crtPartitionSize;
cbk(*threadTask._task, start, end);
}
if (!noWait) {
while (jobCount.load() > 0) {
pool.threadWaiting();
}
}
}
}