- add GroupMemoryBarrierCommand

This commit is contained in:
Magnus Norddahl 2018-06-10 13:35:15 +02:00
parent efa434d47b
commit c9fd52340e
2 changed files with 24 additions and 0 deletions

View file

@ -203,6 +203,8 @@ void DrawerThreads::StopThreads()
shutdown_flag = false;
}
/////////////////////////////////////////////////////////////////////////////
DrawerCommandQueue::DrawerCommandQueue(RenderMemory *frameMemory) : FrameMemory(frameMemory)
{
}
@ -211,3 +213,13 @@ void *DrawerCommandQueue::AllocMemory(size_t size)
{
return FrameMemory->AllocMemory<uint8_t>((int)size);
}
/////////////////////////////////////////////////////////////////////////////
void GroupMemoryBarrierCommand::Execute(DrawerThread *thread)
{
std::unique_lock<std::mutex> lock(mutex);
count++;
condition.notify_all();
condition.wait(lock, [&]() { return count >= thread->num_cores; });
}

View file

@ -97,6 +97,18 @@ public:
virtual void Execute(DrawerThread *thread) = 0;
};
// Wait for all worker threads before executing next command
class GroupMemoryBarrierCommand : public DrawerCommand
{
public:
void Execute(DrawerThread *thread);
private:
std::mutex mutex;
std::condition_variable condition;
size_t count = 0;
};
class DrawerCommandQueue;
typedef std::shared_ptr<DrawerCommandQueue> DrawerCommandQueuePtr;