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 "__execution_fwd.hpp" 19 20 #include "__env.hpp" 21 #include "__receivers.hpp" 22 #include "__schedulers.hpp" 23 24 namespace stdexec { 25 struct inline_scheduler { 26 private: 27 template <class _Receiver> 28 struct __opstate { 29 using __id = __opstate; 30 using __t = __opstate; 31 32 using operation_state_concept = operation_state_t; 33 STDEXEC_ATTRIBUTEstdexec::inline_scheduler::__opstate34 STDEXEC_ATTRIBUTE(host, device) 35 constexpr void start() noexcept { 36 stdexec::set_value(static_cast<_Receiver&&>(__rcvr_)); 37 } 38 39 _Receiver __rcvr_; 40 }; 41 42 struct __attrs { STDEXEC_ATTRIBUTEstdexec::inline_scheduler::__attrs43 STDEXEC_ATTRIBUTE(nodiscard, host, device) 44 static constexpr auto query(get_completion_behavior_t) noexcept { 45 return completion_behavior::inline_completion; 46 } 47 STDEXEC_ATTRIBUTEstdexec::inline_scheduler::__attrs48 STDEXEC_ATTRIBUTE(nodiscard, host, device) 49 static constexpr auto query(get_completion_scheduler_t<set_value_t>) noexcept // 50 -> inline_scheduler { 51 return {}; 52 } 53 }; 54 55 struct __sender { 56 using __id = __sender; 57 using __t = __sender; 58 59 using sender_concept = sender_t; 60 using completion_signatures = stdexec::completion_signatures<set_value_t()>; 61 62 template <class _Receiver> STDEXEC_ATTRIBUTEstdexec::inline_scheduler::__sender63 STDEXEC_ATTRIBUTE(nodiscard, host, device) 64 static constexpr auto connect(_Receiver __rcvr) noexcept -> __opstate<_Receiver> { 65 return {static_cast<_Receiver&&>(__rcvr)}; 66 } 67 STDEXEC_ATTRIBUTEstdexec::inline_scheduler::__sender68 STDEXEC_ATTRIBUTE(nodiscard, host, device) 69 static constexpr auto get_env() noexcept -> __attrs { 70 return {}; 71 } 72 }; 73 74 public: 75 using __t = inline_scheduler; 76 using __id = inline_scheduler; 77 78 using scheduler_concept = scheduler_t; 79 STDEXEC_ATTRIBUTEstdexec::inline_scheduler80 STDEXEC_ATTRIBUTE(nodiscard, host, device) 81 static constexpr auto schedule() noexcept -> __sender { 82 return {}; 83 } 84 85 auto operator==(const inline_scheduler&) const noexcept -> bool = default; 86 }; 87 88 static_assert(__is_scheduler_affine<schedule_result_t<inline_scheduler>>); 89 } // namespace stdexec 90