MCPcopy Create free account
hub / github.com/bshoshany/thread-pool / enqueue_blocks

Function enqueue_blocks

include/BS_thread_pool.hpp:2158–2176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2156 */
2157 template <typename T, typename F, typename R, bool submit, typename N = std::conditional_t<submit, multi_future<R>, void>>
2158 [[nodiscard]] N enqueue_blocks(const T first_index, const T index_after_last, F&& block, std::size_t num_blocks, const priority_t priority = 0)
2159 {
2160 if (index_after_last > first_index)
2161 {
2162 using block_task_t = block_task<T, F, R>;
2163 const std::shared_ptr<std::decay_t<F>> block_ptr = std::make_shared<std::decay_t<F>>(std::forward<F>(block));
2164 const blocks blks(first_index, index_after_last, num_blocks ? num_blocks : thread_count);
2165 num_blocks = blks.get_num_blocks();
2166 std::vector<std::conditional_t<submit, block_task_t, task_t>> all_tasks;
2167 all_tasks.reserve(num_blocks);
2168 for (std::size_t i = 0; i < num_blocks; ++i)
2169 all_tasks.emplace_back(block_task_t{block_ptr, blks.start(i), blks.end(i)});
2170 if constexpr (submit)
2171 return submit_bulk(all_tasks, priority);
2172 else
2173 detach_bulk(all_tasks, priority);
2174 }
2175 return N();
2176 }
2177
2178 /**
2179 * @brief A helper function for `detach_loop()` and `submit_loop()`.

Callers

nothing calls this directly

Calls 5

submit_bulkFunction · 0.85
detach_bulkFunction · 0.85
get_num_blocksMethod · 0.80
endMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected