Toast Engine
Loading...
Searching...
No Matches
wave_executor.hpp
Go to the documentation of this file.
1
11
12#pragma once
13#include <cstddef>
14#include <memory>
15#include <toast/export.hpp>
16#include <type_traits>
17#include <vector>
18
19namespace toast::_detail {
20
21struct WaveJob {
22 std::vector<size_t> items;
23 std::vector<size_t> interpreters;
24};
25
26class ItemRunner {
27public:
28 template<typename Callable>
29 requires(!std::is_same_v<std::remove_cvref_t<Callable>, ItemRunner>)
30 ItemRunner(Callable& callable) noexcept // NOLINT(google-explicit-constructor)
31 : m_object(const_cast<std::remove_const_t<Callable>*>(std::addressof(callable))),
32 m_invoke([](void* object, size_t item) { (*static_cast<Callable*>(object))(item); }) { }
33
34 void operator()(size_t item) const { m_invoke(m_object, item); }
35
36private:
37 void* m_object;
38 void (*m_invoke)(void*, size_t);
39};
40
42 bool non_blocking = true;
43 const char* label = "Wave worker";
44};
45
50TOAST_API void
51 runJobs(const std::vector<WaveJob>& jobs, size_t item_count, ItemRunner run_item, const ExecuteOptions& options = {});
52
53}
Definition wave_executor.hpp:26
Member-robber pattern used by the generated reflection code.
Definition defer.hpp:16
void runJobs(const std::vector< WaveJob > &jobs, size_t item_count, ItemRunner run_item, const ExecuteOptions &options)
Runs the jobs of a plan in parallel and returns once every item has run.
Definition wave_executor.cpp:76
Definition wave_executor.hpp:41
Definition wave_executor.hpp:21