本文整理汇总了C++中WorkItem::workFunction_方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkItem::workFunction_方法的具体用法?C++ WorkItem::workFunction_怎么用?C++ WorkItem::workFunction_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkItem
的用法示例。
在下文中一共展示了WorkItem::workFunction_方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Complete
void WorkQueue::Complete(unsigned priority)
{
completing_ = true;
if (threads_.Size())
{
Resume();
// Take work items also in the main thread until queue empty or no high-priority items anymore
while (!queue_.Empty())
{
queueMutex_.Acquire();
if (!queue_.Empty() && queue_.Front()->priority_ >= priority)
{
WorkItem* item = queue_.Front();
queue_.PopFront();
queueMutex_.Release();
item->workFunction_(item, 0);
item->completed_ = true;
}
else
{
queueMutex_.Release();
break;
}
}
// Wait for threaded work to complete
while (!IsCompleted(priority))
{
}
// If no work at all remaining, pause worker threads by leaving the mutex locked
if (queue_.Empty())
Pause();
}
else
{
// No worker threads: ensure all high-priority items are completed in the main thread
while (!queue_.Empty() && queue_.Front()->priority_ >= priority)
{
WorkItem* item = queue_.Front();
queue_.PopFront();
item->workFunction_(item, 0);
item->completed_ = true;
}
}
PurgeCompleted(priority);
completing_ = false;
}
示例2: ProcessItems
void WorkQueue::ProcessItems(unsigned threadIndex)
{
bool wasActive = false;
for (;;)
{
if (shutDown_)
return;
if (pausing_ && !wasActive)
Time::Sleep(0);
else
{
queueMutex_.Acquire();
if (!queue_.Empty())
{
wasActive = true;
WorkItem* item = queue_.Front();
queue_.PopFront();
queueMutex_.Release();
item->workFunction_(item, threadIndex);
item->completed_ = true;
}
else
{
wasActive = false;
queueMutex_.Release();
Time::Sleep(0);
}
}
}
}
示例3: HandleBeginFrame
void WorkQueue::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
{
// If no worker threads, complete low-priority work here
if (threads_.Empty() && !queue_.Empty())
{
URHO3D_PROFILE(CompleteWorkNonthreaded);
HiresTimer timer;
while (!queue_.Empty() && timer.GetUSec(false) < maxNonThreadedWorkMs_ * 1000)
{
WorkItem* item = queue_.Front();
queue_.PopFront();
item->workFunction_(item, 0);
item->completed_ = true;
}
}
// Complete and signal items down to the lowest priority
PurgeCompleted(0);
PurgePool();
}