6 #ifndef MOTORCORTEX_CORE_CT_THREADPOOL_H
7 #define MOTORCORTEX_CORE_CT_THREADPOOL_H
9 #include "ct_tasksched.h"
10 #include "utl_fncwrapper.h"
11 #include "utl_tsqueue.h"
18 namespace mcx::container {
22 explicit JoinThreads(std::vector<std::thread>& threads) : threads_(threads) {}
25 for (
auto& thread : threads_) {
26 if (thread.joinable())
32 std::vector<std::thread>& threads_;
38 explicit ThreadPool(
size_t thread_count = std::thread::hardware_concurrency());
42 bool setName(std::string name);
44 std::string getName()
const;
46 bool setTaskSched(TaskSched task_sched,
int task_prio = 0);
48 std::tuple<TaskSched, int> getTaskSched()
const;
50 bool setCpuAffinity(
const std::vector<uint32_t>& cpu_affinity_list);
52 std::vector<uint32_t> getCpuAffinity()
const;
54 template <
typename FunctionType>
55 std::future<
typename std::result_of<FunctionType()>::type> submit(FunctionType f) {
56 typedef typename std::result_of<FunctionType()>::type result_type;
57 std::packaged_task<result_type()> task(std::move(f));
58 std::future<result_type> res(task.get_future());
59 work_queue_.push(std::move(task));
68 static constexpr
size_t MAX_THREAD_NAME_LEN = 16;
69 std::vector<std::thread> threads_;
70 std::vector<std::thread::native_handle_type> ids_;
72 std::atomic_bool done_{};
73 std::atomic_int counter_{};
79 #endif // MOTORCORTEX_CORE_CT_THREADPOOL_H