mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-25 17:35:58 +00:00
25 lines
646 B
C++
25 lines
646 B
C++
#pragma once
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <thread>
|
|
#include <condition_variable>
|
|
#include <queue>
|
|
|
|
namespace bumbleBee {
|
|
template <typename FuncRet, typename FuncParam>
|
|
class ThreadPool {
|
|
public:
|
|
ThreadPool() = delete;
|
|
ThreadPool(std::int32_t threadCount);
|
|
|
|
std::thread::id execute(std::function<FuncRet(FuncParam)> function);
|
|
void gracefullStop(std::thread::id thread);
|
|
void gracefullAllStop();
|
|
private:
|
|
std::mutex mutex_;
|
|
std::condition_variable condition_;
|
|
std::int32_t threadCount_;
|
|
std::vector<std::thread> threadPool_;
|
|
std::unordered_map<std::thread, std::bool> terminating_;
|
|
};
|
|
} |