1 /*
2  * Copyright (c) 2021-2024 NVIDIA Corporation
3  *
4  * Licensed under the Apache License Version 2.0 with LLVM Exceptions
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  *   https://llvm.org/LICENSE.txt
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "__basic_sender.hpp"
19 #include "__cpo.hpp"
20 #include "__env.hpp"
21 #include "__execution_fwd.hpp"
22 #include "__receivers.hpp"
23 #include "__schedulers.hpp"
24 #include "__utility.hpp"
25 
26 namespace stdexec
27 {
28 namespace __inln
29 {
30 struct __schedule_t
31 {};
32 
33 struct __scheduler
34 {
35     using __t = __scheduler;
36     using __id = __scheduler;
37 
38     template <class _Tag = __schedule_t>
39     STDEXEC_ATTRIBUTE((host, device))
STDEXEC_MEMFN_DECLstdexec::__inln::__scheduler40     STDEXEC_MEMFN_DECL(auto schedule)(this __scheduler)
41     {
42         return __make_sexpr<_Tag>();
43     }
44 
querystdexec::__inln::__scheduler45     auto query(get_forward_progress_guarantee_t) const noexcept
46         -> forward_progress_guarantee
47     {
48         return forward_progress_guarantee::weakly_parallel;
49     }
50 
51     auto operator==(const __scheduler&) const noexcept -> bool = default;
52 };
53 
54 struct __env
55 {
querystdexec::__inln::__env56     static constexpr bool query(__is_scheduler_affine_t) noexcept
57     {
58         return true;
59     }
60 
querystdexec::__inln::__env61     constexpr auto query(get_completion_scheduler_t<set_value_t>) const noexcept
62         -> __scheduler
63     {
64         return {};
65     }
66 };
67 } // namespace __inln
68 
69 template <>
70 struct __sexpr_impl<__inln::__schedule_t> : __sexpr_defaults
71 {
72     static constexpr auto get_attrs = //
__anond6e5414a0102stdexec::__sexpr_impl73         [](__ignore) noexcept { return __inln::__env(); };
74 
75     static constexpr auto get_completion_signatures = //
76         [](__ignore,
__anond6e5414a0202stdexec::__sexpr_impl77            __ignore = {}) noexcept -> completion_signatures<set_value_t()> {
78         return {};
79     };
80 
81     static constexpr auto start = //
82         []<class _Receiver>(__ignore, _Receiver& __rcvr) noexcept -> void {
83         stdexec::set_value(static_cast<_Receiver&&>(__rcvr));
84     };
85 };
86 
87 static_assert(__is_scheduler_affine<schedule_result_t<__inln::__scheduler>>);
88 } // namespace stdexec
89