diff --git a/src/common/functionpool.cpp b/src/common/functionpool.cpp deleted file mode 100644 index 894afa97a..000000000 --- a/src/common/functionpool.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "functionpool.hpp" - -#include - -namespace kb { -namespace viz2d { -namespace detail { - -FunctionPool::FunctionPool() : - m_function_queue(), m_lock(), m_data_condition(), m_accept_functions(true) { -} - -FunctionPool::~FunctionPool() { -} - -void FunctionPool::push(std::function func) { - std::unique_lock lock(m_lock); - m_function_queue.push(func); - // when we send the notification immediately, the consumer will try to get the lock , so unlock asap - lock.unlock(); - m_data_condition.notify_one(); -} - -void FunctionPool::done() { - std::unique_lock lock(m_lock); - m_accept_functions = false; - lock.unlock(); - // when we send the notification immediately, the consumer will try to get the lock , so unlock asap - m_data_condition.notify_all(); - //notify all waiting threads. -} - -void FunctionPool::infinite_loop_func() { - std::function func; - while (true) { - try { - { - std::unique_lock lock(m_lock); - m_data_condition.wait(lock, [this]() { - return !m_function_queue.empty() || !m_accept_functions; - }); - if (!m_accept_functions && m_function_queue.empty()) { - //lock will be release automatically. - //finish the thread loop and let it join in the main thread. - return; - } - func = m_function_queue.front(); - m_function_queue.pop(); - //release the lock - } - func(); - } catch(std::exception& ex) { - std::cerr << ex.what() << std::endl; - } - } - -} - -} /* namespace detail */ -} /* namespace viz2d */ -} /* namespace kb */ diff --git a/src/common/functionpool.hpp b/src/common/functionpool.hpp deleted file mode 100644 index 2019965b5..000000000 --- a/src/common/functionpool.hpp +++ /dev/null @@ -1,37 +0,0 @@ -//started with https://stackoverflow.com/a/51400041/1884837 -#ifndef SRC_COMMON_FUNCTIONPOOL_HPP_ -#define SRC_COMMON_FUNCTIONPOOL_HPP_ - -#include -#include -#include -#include -#include -#include - -namespace kb { -namespace viz2d { -namespace detail { - -class FunctionPool { - -private: - std::queue> m_function_queue; - std::mutex m_lock; - std::condition_variable m_data_condition; - std::atomic m_accept_functions; - -public: - - FunctionPool(); - ~FunctionPool(); - void push(std::function func); - void done(); - void infinite_loop_func(); -}; - -} /* namespace detail */ -} /* namespace viz2d */ -} /* namespace kb */ - -#endif /* SRC_COMMON_FUNCTIONPOOL_HPP_ */