From 075d17f8ada47e990fe94606c3d21df409223465 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 2 May 2023 10:01:47 +0200 Subject: moved source directories into `/src` (#264) * moved source directories into `/src` * updated bundle.lua for new `src` path * moved some docs, icon * removed old test trees --- zencore/workthreadpool.cpp | 83 ---------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 zencore/workthreadpool.cpp (limited to 'zencore/workthreadpool.cpp') diff --git a/zencore/workthreadpool.cpp b/zencore/workthreadpool.cpp deleted file mode 100644 index b4328cdbd..000000000 --- a/zencore/workthreadpool.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include - -#include - -namespace zen { - -namespace detail { - struct LambdaWork : IWork - { - LambdaWork(auto Work) : WorkFunction(Work) {} - virtual void Execute() override { WorkFunction(); } - - std::function WorkFunction; - }; -} // namespace detail - -WorkerThreadPool::WorkerThreadPool(int InThreadCount) -{ - for (int i = 0; i < InThreadCount; ++i) - { - m_WorkerThreads.emplace_back(&WorkerThreadPool::WorkerThreadFunction, this); - } -} - -WorkerThreadPool::~WorkerThreadPool() -{ - m_WorkQueue.CompleteAdding(); - - for (std::thread& Thread : m_WorkerThreads) - { - Thread.join(); - } - - m_WorkerThreads.clear(); -} - -void -WorkerThreadPool::ScheduleWork(Ref Work) -{ - m_WorkQueue.Enqueue(std::move(Work)); -} - -void -WorkerThreadPool::ScheduleWork(std::function&& Work) -{ - m_WorkQueue.Enqueue(Ref(new detail::LambdaWork(Work))); -} - -[[nodiscard]] size_t -WorkerThreadPool::PendingWork() const -{ - return m_WorkQueue.Size(); -} - -void -WorkerThreadPool::WorkerThreadFunction() -{ - do - { - Ref Work; - if (m_WorkQueue.WaitAndDequeue(Work)) - { - try - { - Work->Execute(); - } - catch (std::exception& e) - { - Work->m_Exception = std::current_exception(); - - ZEN_WARN("Caught exception in worker thread: {}", e.what()); - } - } - else - { - return; - } - } while (true); -} - -} // namespace zen -- cgit v1.2.3