/* * This file is part of the Flowee project * Copyright (C) 2018 Tom Zander * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef WORKERTHREADS_H #define WORKERTHREADS_H #include #include class WorkerThreads { public: WorkerThreads(); ~WorkerThreads(); void stopThreads(); void joinAll(); boost::asio::io_service& ioService() const; /** * Wrapper function that allows users to create a thread on our thread-group. */ template boost::thread* createNewThread(F threadfunc) { return m_threads.create_thread(threadfunc); } protected: /// only called from constructor. Useful in unit tests. void startThreads(); private: std::shared_ptr m_ioservice; std::unique_ptr m_work; boost::thread_group m_threads; }; #endif