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