Exemple #1
0
void Renderer::ProcessThread( std::shared_ptr<Thread_InitParam> param )
{
    Task task;

    auto shared = Create_Thread_SharedData();

    shared->rng = std::make_shared<Random>((unsigned long)std::time(nullptr) + param->id);
    shared->color.assign(commonConfig->width * commonConfig->height, Vec3d());

    threadSharedData.push_back(shared);

    InitializeThread(param, shared);

    while (!queue.Done())
    {
        queue.Dequeue(task);

        if (queue.Done())
        {
            break;
        }

        switch (task.command)
        {
        case Command::Render:
        {
            ProcessThread_Render(shared);
            break;
        }

        case Command::UpdateImage:
        {
            image->Accumulate(Vec4i(0, 0, commonConfig->width, commonConfig->height), shared->color);
            shared->color.assign(commonConfig->width * commonConfig->height, Vec3d());
            break;
        }
        }

        // Barrier
        if (task.needSync)
        {
            std::unique_lock<std::mutex> lock(taskSyncMutex);

            if (++waitingThreads == commonConfig->numThreads)
            {
                waitingThreads = 0;
                taskSync.notify_all();
            }
            else
            {
                taskSync.wait(lock);
            }
        }

        {
            std::unique_lock<std::mutex> lock(taskFinishedMutex);
            finishedTasks++;
            taskFinished.notify_one();
        }
    }
}
Exemple #2
0
void CReadThread::run( )
{
    InitializeThread( );
    exec( );
}