Another race condition fix

This commit is contained in:
Jack Andersen 2016-04-09 13:18:12 -10:00
parent 5fc5442286
commit 6945ec94b8
2 changed files with 10 additions and 0 deletions

View File

@ -17,6 +17,7 @@ class ClientProcess
std::mutex m_mutex; std::mutex m_mutex;
std::condition_variable m_cv; std::condition_variable m_cv;
std::condition_variable m_initCv; std::condition_variable m_initCv;
std::condition_variable m_waitCv;
int m_verbosity; int m_verbosity;
public: public:
@ -87,6 +88,7 @@ public:
const LambdaTransaction* addLambdaTransaction(std::function<void(BlenderToken&)>&& func); const LambdaTransaction* addLambdaTransaction(std::function<void(BlenderToken&)>&& func);
bool syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, BlenderToken& btok); bool syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, BlenderToken& btok);
void swapCompletedQueue(std::list<std::unique_ptr<Transaction>>& queue); void swapCompletedQueue(std::list<std::unique_ptr<Transaction>>& queue);
void waitUntilComplete();
void shutdown(); void shutdown();
}; };

View File

@ -77,6 +77,7 @@ void ClientProcess::Worker::proc()
lk.lock(); lk.lock();
m_proc.m_completedQueue.push_back(std::move(trans)); m_proc.m_completedQueue.push_back(std::move(trans));
} }
m_proc.m_waitCv.notify_one();
if (!m_proc.m_running) if (!m_proc.m_running)
break; break;
m_proc.m_cv.wait(lk); m_proc.m_cv.wait(lk);
@ -154,6 +155,13 @@ void ClientProcess::swapCompletedQueue(std::list<std::unique_ptr<Transaction>>&
queue.swap(m_completedQueue); queue.swap(m_completedQueue);
} }
void ClientProcess::waitUntilComplete()
{
std::unique_lock<std::mutex> lk(m_mutex);
while (m_pendingQueue.size())
m_waitCv.wait(lk);
}
void ClientProcess::shutdown() void ClientProcess::shutdown()
{ {
if (!m_running) if (!m_running)