asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
task.hpp
1
11#pragma once
12
13#include "../asrtl/status.h"
14
15#include <ecor/ecor.hpp>
16
17namespace asrt
18{
19
21{
22 void* allocate( std::size_t n, std::size_t ) { return malloc( n ); }
23
24 void deallocate( void* p, std::size_t, std::size_t ) noexcept { std::free( p ); }
25};
26
30{
31 task_ctx( auto& mem_res )
32 : _memory_resource( mem_res )
33 {
34 }
35
36 void tick() { _core.run_once(); }
37
38 auto& query( ecor::get_memory_resource_t ) { return _memory_resource; }
39
40 auto& query( ecor::get_task_core_t ) { return _core; }
41
42 void reschedule( ecor::schedulable& s ) { _core.reschedule( s ); }
43
44private:
45 ecor::task_memory_resource _memory_resource;
46 ecor::task_core _core;
47};
48
49using status = asrt_status;
50using ecor::suspend;
51
53{
54};
55static constexpr test_fail_t test_fail{};
56
59{
60 using extra_error_signatures = ecor::
61 completion_signatures< ecor::set_error_t( status ), ecor::set_error_t( test_fail_t ) >;
62 using trace_type = ecor::task_default_trace;
63};
64
67template < typename T >
68using task = ecor::task< T, asrt::task_cfg >;
69
74{
75 using sender_concept = ecor::sender_t;
76 using completion_signatures =
77 ecor::completion_signatures< ecor::set_value_t(), ecor::set_error_t( status ) >;
78
79 asrt_status status;
80
81 status_sender( asrt_status s )
82 : status( s )
83 {
84 }
85
86 template < ecor::receiver R >
87 struct op
88 {
89 asrt_status s;
90 R recv;
91
92 void start()
93 {
94 if ( s == ASRT_SUCCESS )
95 recv.set_value();
96 else
97 recv.set_error( s );
98 }
99 };
100
101 template < ecor::receiver R >
102 auto connect( R&& r ) && noexcept
103 {
104 return op< R >{ status, (R&&) r };
105 }
106
107 constexpr operator asrt_status() const { return status; }
108 constexpr bool operator==( asrt_status st ) const { return status == st; }
109};
110
111} // namespace asrt
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: callback.hpp:17
ecor::task< T, asrt::task_cfg > task
Coroutine task type used throughout asrt's C++ layer.
Definition: task.hpp:68
Definition: task.hpp:21
Definition: task.hpp:88
Sender that completes with success if the contained status is ASRT_SUCCESS, and with test_fail otherw...
Definition: task.hpp:74
Error signatures and trace policy used by all asrt tasks.
Definition: task.hpp:59
Event-loop context that owns a coroutine task scheduler.
Definition: task.hpp:30
Definition: task.hpp:53