From 9d72601f9ada30992c990c3778215a7b1dce4c74 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 31 Mar 2016 18:24:28 -1000 Subject: [PATCH] LambdaTransaction added to ClientProcess --- hecl/extern/boo | 2 +- hecl/include/hecl/ClientProcess.hpp | 11 ++++++++++- hecl/lib/ClientProcess.cpp | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/hecl/extern/boo b/hecl/extern/boo index 679ba36c4..83f55a54d 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 679ba36c4c53e16d749bc88b697ea8316b4f7dae +Subproject commit 83f55a54d9abdac3d9f25893a53147798fcce864 diff --git a/hecl/include/hecl/ClientProcess.hpp b/hecl/include/hecl/ClientProcess.hpp index 09ff5d28c..be9a6f62c 100644 --- a/hecl/include/hecl/ClientProcess.hpp +++ b/hecl/include/hecl/ClientProcess.hpp @@ -25,7 +25,8 @@ public: enum class Type { Buffer, - Cook + Cook, + Lambda } m_type; bool m_complete = false; virtual void run(BlenderToken& btok)=0; @@ -53,6 +54,13 @@ public: CookTransaction(ClientProcess& parent, const ProjectPath& path, Database::IDataSpec* spec) : Transaction(parent, Type::Cook), m_path(path), m_dataSpec(spec) {} }; + struct LambdaTransaction : Transaction + { + std::function m_func; + void run(BlenderToken& btok); + LambdaTransaction(ClientProcess& parent, std::function&& func) + : Transaction(parent, Type::Lambda), m_func(std::move(func)) {} + }; private: std::list> m_pendingQueue; std::list> m_completedQueue; @@ -74,6 +82,7 @@ public: const BufferTransaction* addBufferTransaction(const hecl::ProjectPath& path, void* target, size_t maxLen, size_t offset); const CookTransaction* addCookTransaction(const hecl::ProjectPath& path, Database::IDataSpec* spec); + const LambdaTransaction* addLambdaTransaction(std::function&& func); bool syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, BlenderToken& btok); void swapCompletedQueue(std::list>& queue); void shutdown(); diff --git a/hecl/lib/ClientProcess.cpp b/hecl/lib/ClientProcess.cpp index 63822e694..a91b5d352 100644 --- a/hecl/lib/ClientProcess.cpp +++ b/hecl/lib/ClientProcess.cpp @@ -46,6 +46,12 @@ void ClientProcess::CookTransaction::run(BlenderToken& btok) m_complete = true; } +void ClientProcess::LambdaTransaction::run(BlenderToken& btok) +{ + m_func(btok); + m_complete = true; +} + ClientProcess::Worker::Worker(ClientProcess& proc) : m_proc(proc) { @@ -66,8 +72,11 @@ void ClientProcess::Worker::proc() lk.lock(); m_proc.m_completedQueue.push_back(std::move(trans)); } + if (!m_proc.m_running) + break; m_proc.m_cv.wait(lk); } + m_blendTok.shutdown(); } ClientProcess::ClientProcess(int verbosityLevel) @@ -100,6 +109,16 @@ ClientProcess::addCookTransaction(const hecl::ProjectPath& path, Database::IData return ret; } +const ClientProcess::LambdaTransaction* +ClientProcess::addLambdaTransaction(std::function&& func) +{ + std::unique_lock lk(m_mutex); + LambdaTransaction* ret = new LambdaTransaction(*this, std::move(func)); + m_pendingQueue.emplace_back(ret); + m_cv.notify_one(); + return ret; +} + bool ClientProcess::syncCook(const hecl::ProjectPath& path, Database::IDataSpec* spec, BlenderToken& btok) { if (spec->canCook(path, btok))