summaryrefslogtreecommitdiff
path: root/Source/Core/Common/WorkQueueThread.h
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2019-10-13 15:24:56 -0400
committerGitHub <noreply@github.com>2019-10-13 15:24:56 -0400
commitd39555919d39357b49a7eb02f2d96b9a71bf128b (patch)
treed3174dca1087b87d58b4747f22c9d07bdd9727f0 /Source/Core/Common/WorkQueueThread.h
parentaba23c8d87872836de73dcded82a01c03295d93f (diff)
parent26ebf5b65088062e4f3290b89a973fa3ef3eee1a (diff)
Merge pull request #8395 from CookiePLMonster/improve-work-queue
Improvements to WorkQueueThread
Diffstat (limited to 'Source/Core/Common/WorkQueueThread.h')
-rw-r--r--Source/Core/Common/WorkQueueThread.h19
1 files changed, 9 insertions, 10 deletions
diff --git a/Source/Core/Common/WorkQueueThread.h b/Source/Core/Common/WorkQueueThread.h
index 426d8b493d..e5dfac8b49 100644
--- a/Source/Core/Common/WorkQueueThread.h
+++ b/Source/Core/Common/WorkQueueThread.h
@@ -27,14 +27,14 @@ public:
Shutdown();
m_shutdown.Clear();
m_function = std::move(function);
- m_thread = std::thread([this] { ThreadLoop(); });
+ m_thread = std::thread(&WorkQueueThread::ThreadLoop, this);
}
template <typename... Args>
void EmplaceItem(Args&&... args)
{
{
- std::unique_lock<std::mutex> lg(m_lock);
+ std::lock_guard lg(m_lock);
m_items.emplace(std::forward<Args>(args)...);
}
m_wakeup.Set();
@@ -59,14 +59,13 @@ private:
while (true)
{
- T item;
- {
- std::unique_lock<std::mutex> lg(m_lock);
- if (m_items.empty())
- break;
- item = m_items.front();
- m_items.pop();
- }
+ std::unique_lock lg(m_lock);
+ if (m_items.empty())
+ break;
+ T item{std::move(m_items.front())};
+ m_items.pop();
+ lg.unlock();
+
m_function(std::move(item));
}