mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
Merge pull request #8395 from CookiePLMonster/improve-work-queue
Improvements to WorkQueueThread
This commit is contained in:
commit
d39555919d
@ -27,14 +27,14 @@ public:
|
|||||||
Shutdown();
|
Shutdown();
|
||||||
m_shutdown.Clear();
|
m_shutdown.Clear();
|
||||||
m_function = std::move(function);
|
m_function = std::move(function);
|
||||||
m_thread = std::thread([this] { ThreadLoop(); });
|
m_thread = std::thread(&WorkQueueThread::ThreadLoop, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void EmplaceItem(Args&&... 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_items.emplace(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
m_wakeup.Set();
|
m_wakeup.Set();
|
||||||
@ -59,14 +59,13 @@ private:
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
T item;
|
std::unique_lock lg(m_lock);
|
||||||
{
|
if (m_items.empty())
|
||||||
std::unique_lock<std::mutex> lg(m_lock);
|
break;
|
||||||
if (m_items.empty())
|
T item{std::move(m_items.front())};
|
||||||
break;
|
m_items.pop();
|
||||||
item = m_items.front();
|
lg.unlock();
|
||||||
m_items.pop();
|
|
||||||
}
|
|
||||||
m_function(std::move(item));
|
m_function(std::move(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user