当前位置: 首页>>代码示例>>C++>>正文


C++ WorkItem::workFunction_方法代码示例

本文整理汇总了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;
}
开发者ID:boberfly,项目名称:Urho3D,代码行数:51,代码来源:WorkQueue.cpp

示例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);
            }
        }
    }
}
开发者ID:boberfly,项目名称:Urho3D,代码行数:34,代码来源:WorkQueue.cpp

示例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();
}
开发者ID:boberfly,项目名称:Urho3D,代码行数:22,代码来源:WorkQueue.cpp


注:本文中的WorkItem::workFunction_方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。