execution 1.0.1
Portable task execution, timers, and process lifecycle
Loading...
Searching...
No Matches
default_executor.hpp
Go to the documentation of this file.
1/*
2 Copyright 2015 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6
7/**************************************************************************************************/
8
9#ifndef STLAB_CONCURRENCY_DEFAULT_EXECUTOR_HPP
10#define STLAB_CONCURRENCY_DEFAULT_EXECUTOR_HPP
11
39
41#include <stlab/execution/config.hpp>
42
43#include <cstdint>
44#include <type_traits>
45#include <utility>
46
47/**************************************************************************************************/
48
49namespace stlab {
50inline namespace v2 {
51
60
64using stlab_v2_task_proc = void (*)(void*) noexcept;
65
74extern "C" void stlab_v2_default_executor_submit(const unsigned char* task_abi_guard,
75 const stlab_v2_task_concept* vtable,
76 stlab_v2_task_proc invoke,
77 void* source) noexcept;
78
87extern "C" void stlab_v2_high_executor_submit(const unsigned char* task_abi_guard,
88 const stlab_v2_task_concept* vtable,
89 stlab_v2_task_proc invoke,
90 void* source) noexcept;
91
100extern "C" void stlab_v2_low_executor_submit(const unsigned char* task_abi_guard,
101 const stlab_v2_task_concept* vtable,
102 stlab_v2_task_proc invoke,
103 void* source) noexcept;
104
111
113extern "C" std::int32_t stlab_v2_default_executor_supports_blocking() noexcept;
114
116
117} // namespace v2
118
119STLAB_EXECUTION_VERSION_NAMESPACE_BEGIN()
120
126
127/**************************************************************************************************/
128
129namespace execution_detail {
130
131/**************************************************************************************************/
132
133enum class executor_priority : std::uint8_t { high, medium, low };
134
140inline void submit_executor_proc(executor_priority priority, task<void() noexcept>& t) {
141 const auto* task_abi_guard = &current_task_storage_abi_guard::value;
142 const auto* vtable = t.relocation_concept();
143 const auto invoke = t.relocation_invoke();
144 auto* source = t.relocation_source();
145 switch (priority) {
146 case executor_priority::high:
147 stlab_v2_high_executor_submit(task_abi_guard, vtable, invoke, source);
148 break;
149 case executor_priority::medium:
150 stlab_v2_default_executor_submit(task_abi_guard, vtable, invoke, source);
151 break;
152 case executor_priority::low:
153 stlab_v2_low_executor_submit(task_abi_guard, vtable, invoke, source);
154 break;
155 }
156}
157
158/**************************************************************************************************/
159
160template <executor_priority P = executor_priority::medium>
161struct executor_type {
162 using result_type = void;
163
168 template <class F>
169 auto operator()(F&& f) const -> std::enable_if_t<std::is_nothrow_invocable_v<std::decay_t<F>>> {
170 task<void() noexcept> t{std::forward<F>(f)};
171 submit_executor_proc(P, t);
172 }
173};
174
175/**************************************************************************************************/
176
177} // namespace execution_detail
178
179/**************************************************************************************************/
180
183inline constexpr auto low_executor =
184 execution_detail::executor_type<execution_detail::executor_priority::low>{};
185
186inline constexpr auto default_executor =
187 execution_detail::executor_type<execution_detail::executor_priority::medium>{};
188
190inline constexpr auto high_executor =
191 execution_detail::executor_type<execution_detail::executor_priority::high>{};
192
193/**************************************************************************************************/
194
196
197STLAB_EXECUTION_VERSION_NAMESPACE_END()
198} // namespace stlab
199
200/**************************************************************************************************/
201
202#endif
203
204/**************************************************************************************************/
constexpr auto low_executor
Low-priority concurrent executor. Portable executors prioritize queued work without changing OS threa...
Definition default_executor.hpp:183
constexpr auto default_executor
Default concurrent executor using the medium-priority queue.
Definition default_executor.hpp:186
constexpr auto high_executor
High-priority concurrent executor. Portable executors prioritize queued work without changing OS thre...
Definition default_executor.hpp:190
std::int32_t stlab_v2_default_executor_supports_blocking() noexcept
Returns one when the configured core supports blocking waits, otherwise zero.
void stlab_v2_default_executor_submit(const unsigned char *task_abi_guard, const stlab_v2_task_concept *vtable, stlab_v2_task_proc invoke, void *source) noexcept
Submits one task to the shared default-priority executor.
void stlab_v2_low_executor_submit(const unsigned char *task_abi_guard, const stlab_v2_task_concept *vtable, stlab_v2_task_proc invoke, void *source) noexcept
Submits one task to the shared low-priority executor.
void stlab_v2_high_executor_submit(const unsigned char *task_abi_guard, const stlab_v2_task_concept *vtable, stlab_v2_task_proc invoke, void *source) noexcept
Submits one task to the shared high-priority executor.
void stlab_v2_notify_default_executor_before_waiting() noexcept
Notifies the shared default executor that the calling thread is about to wait.
void(*)(void *) noexcept stlab_v2_task_proc
Function pointer type submitted through the shared executor ABI.
Definition default_executor.hpp:64
typename noexcept_deducer< task_, F >::type task
task_ with noexcept deduced from the function type F (e.g. void() vs void() noexcept).
Definition task.hpp:453
Definition default_executor.hpp:50
Definition default_executor.hpp:49
Versioned operation table used to relocate a task target across the shared executor ABI.
Definition task.hpp:64
Move-only callable wrapper for executor scheduling (task<Signature>).