1 #ifndef LIBJMMCG_CORE_PRIVATE_FIXED_THREADS_CONTAINER_HPP
2 #define LIBJMMCG_CORE_PRIVATE_FIXED_THREADS_CONTAINER_HPP
22 #include "../../core/config.h"
23 #include "../../core/trace.hpp"
28 #include <unordered_map>
46 using pool_traits_type=PTT;
47 using os_traits=
typename pool_traits_type::os_traits;
48 using thread_traits=
typename os_traits::thread_traits;
62 fixed_pool_of_threads(size_type
const sz, exit_requested_type &exit_requested,
typename internal_container_type::value_type::signalled_work_queue_type &signalled_work_queue)
noexcept(
false) {
64 lookup_table.reserve(sz);
65 lookup_table.rehash(sz);
66 for (size_type i=0; i<sz; ++i) {
67 pool.emplace_back(std::ref(exit_requested), std::ref(signalled_work_queue));
68 auto a_thread=std::next(pool.begin(), pool.size()-1);
69 a_thread->create_running();
70 typename thread_traits::api_params_type::processor_mask_type mask(i);
72 a_thread->kernel_affinity(mask);
73 }
catch (
typename thread_type::exception_type
const &ex) {
76 const auto tid=a_thread->params().id;
77 lookup_table.insert(
typename container_type::value_type(tid, a_thread));
79 assert(pool.size()==lookup_table.size());
85 lookup_table.reserve(sz);
86 lookup_table.rehash(sz);
87 for (size_type i=0; i<sz; ++i) {
88 pool.emplace_back(std::ref(exit_requested));
89 auto a_thread=std::next(pool.begin(), pool.size()-1);
90 a_thread->create_running();
91 typename thread_traits::api_params_type::processor_mask_type mask(i);
93 a_thread->kernel_affinity(mask);
94 }
catch (
typename thread_type::exception_type
const &ex) {
97 const auto tid=a_thread->params().id;
98 lookup_table.insert(
typename container_type::value_type(tid, a_thread));
100 assert(pool.size()==lookup_table.size());
110 return *pool.begin();
113 return *pool.begin();
117 return lookup_table.end();
121 return lookup_table.find(key);
125 return lookup_table.find(key);
129 assert(lookup_table.empty()==pool.empty());
134 const size_type sz=lookup_table.size();
135 [[maybe_unused]]
const size_type currently_running=num_running();
136 assert(sz>=currently_running);
142 assert(lookup_table.size()>=num_running());
143 lookup_table.clear();
148 template<
class S>
friend
150 template<
class S>
friend
152 internal_container_type pool;
153 container_type lookup_table;
155 internal_container_type
const &
__fastcall colln()
const noexcept(
true)
FORCE_INLINE {
159 size_type num_running()
const noexcept(
true)
FORCE_INLINE {
160 assert(pool.size()==lookup_table.size());
161 return std::accumulate(
165 [](size_type
const s,
typename internal_container_type::const_iterator::value_type
const &v) {
166 return s+
static_cast<size_type>(v.is_running());