From 6945ec94b811aeedf475bb7d20813500809b9665 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 9 Apr 2016 13:18:12 -1000 Subject: [PATCH] Another race condition fix --- hecl/include/hecl/ClientProcess.hpp | 2 ++ hecl/lib/ClientProcess.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/hecl/include/hecl/ClientProcess.hpp b/hecl/include/hecl/ClientProcess.hpp index bd05071e4..f3b0097a7 100644 --- a/hecl/include/hecl/ClientProcess.hpp +++ b/hecl/include/hecl/ClientProcess.hpp @@ -17,6 +17,7 @@ class ClientProcess std::mutex m_mutex; std::condition_variable m_cv; std::condition_variable m_initCv; + std::condition_variable m_waitCv; int m_verbosity; public: @@ -87,6 +88,7 @@ public: const LambdaTransaction* addLambdaTransaction(std::function&& func); bool syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, BlenderToken& btok); void swapCompletedQueue(std::list>& queue); + void waitUntilComplete(); void shutdown(); }; diff --git a/hecl/lib/ClientProcess.cpp b/hecl/lib/ClientProcess.cpp index 69d1358c2..168829507 100644 --- a/hecl/lib/ClientProcess.cpp +++ b/hecl/lib/ClientProcess.cpp @@ -77,6 +77,7 @@ void ClientProcess::Worker::proc() lk.lock(); m_proc.m_completedQueue.push_back(std::move(trans)); } + m_proc.m_waitCv.notify_one(); if (!m_proc.m_running) break; m_proc.m_cv.wait(lk); @@ -154,6 +155,13 @@ void ClientProcess::swapCompletedQueue(std::list>& queue.swap(m_completedQueue); } +void ClientProcess::waitUntilComplete() +{ + std::unique_lock lk(m_mutex); + while (m_pendingQueue.size()) + m_waitCv.wait(lk); +} + void ClientProcess::shutdown() { if (!m_running)