10#include "ublk/ublk_cmd.h"
16template <
typename Sched,
typename Alloc>
struct TaskEnv {
17 using start_scheduler_type = Sched;
18 using allocator_type = Alloc;
20 const ublksrv_ctrl_dev_info *info =
nullptr;
22 template <
typename>
using env_type = TaskEnv;
24 template <
typename Env>
25 requires requires(
const Env &env) { env.query(fetch_dev_info_t{}); }
26 constexpr TaskEnv(
const Env &env) noexcept
27 : info(env.query(fetch_dev_info_t{})) {}
29 constexpr TaskEnv() noexcept = default;
32 constexpr auto query(fetch_dev_info_t) const noexcept {
37struct get_allocator_with_default_t {
38 template <
typename Env>
39 requires requires(Env
const &env) { ex::get_allocator(env); }
40 constexpr auto operator()(Env
const &env)
const noexcept {
41 return ex::get_allocator(env);
44 template <
typename Env>
45 requires(!
requires(Env
const &env) { ex::get_allocator(env); })
46 constexpr std::allocator<std::byte>
operator()(Env
const &)
const noexcept {
51inline constexpr get_allocator_with_default_t get_allocator_with_default{};
53template <
typename TaskFn,
typename... Args>
54auto task_invoke(TaskFn &&task_fn, Args &&...args)
noexcept {
55 return ex::read_env(ex::get_start_scheduler) |
56 ex::let_value([task_fn = std::forward<TaskFn>(task_fn),
57 ... args = std::forward<Args>(args)](
58 const auto &sched)
noexcept {
59 using Sched = std::decay_t<
decltype(sched)>;
60 return ex::read_env(get_allocator_with_default) |
61 ex::let_value([task_fn = std::move(task_fn),
62 ... args = std::move(args)](
63 const auto &alloc)
mutable {
64 using Alloc = std::decay_t<
decltype(alloc)>;
65 return std::move(task_fn)
66 .template invoke<Sched, Alloc>(
The std::execution backend namespace used by ublk-cpp.
The main namespace of the ublk-cpp library.
Environment queries used by the library's senders.