/** * libdatachannel streamer example * Copyright (c) 2020 Filip Klembara (in2core) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef dispatchqueue_hpp #define dispatchqueue_hpp #include #include #include #include #include #include class DispatchQueue { typedef std::function fp_t; public: DispatchQueue(std::string name, size_t threadCount = 1); ~DispatchQueue(); // dispatch and copy void dispatch(const fp_t& op); // dispatch and move void dispatch(fp_t&& op); void removePending(); // Deleted operations DispatchQueue(const DispatchQueue& rhs) = delete; DispatchQueue& operator=(const DispatchQueue& rhs) = delete; DispatchQueue(DispatchQueue&& rhs) = delete; DispatchQueue& operator=(DispatchQueue&& rhs) = delete; private: std::string name; std::mutex lockMutex; std::vector threads; std::queue queue; std::condition_variable condition; bool quit = false; void dispatchThreadHandler(void); }; #endif /* dispatchqueue_hpp */