77// Official repository: https://github.com/cppalliance/capy
88//
99
10+ #include < boost/capy/concept/execution_context.hpp>
1011#include < boost/capy/ex/run_async.hpp>
11- #include < boost/capy/ex/execution_context.hpp>
1212#include < boost/capy/ex/run.hpp>
1313#include < boost/capy/ex/strand.hpp>
1414#include < boost/capy/task.hpp>
@@ -21,48 +21,53 @@ using namespace boost::capy;
2121
2222// -----------------------------------------------
2323//
24- // Test Execution Context
24+ // Bench Execution Context
2525//
2626// A minimal execution context for benchmarking.
2727//
2828// -----------------------------------------------
2929
30- class test_context : public execution_context
30+ class bench_io_context : public execution_context
3131{
3232public:
33- ~test_context ()
33+ class executor_type ;
34+
35+ ~bench_io_context ()
3436 {
3537 shutdown ();
3638 destroy ();
3739 }
40+
41+ executor_type
42+ get_executor () noexcept ;
3843};
3944
4045// -----------------------------------------------
4146//
42- // Test Executor
47+ // Bench Executor
4348//
4449// A minimal executor that satisfies the capy
4550// Executor concept. Dispatches inline for
4651// benchmarking pure coroutine overhead.
4752//
4853// -----------------------------------------------
4954
50- class test_executor
55+ class bench_io_context ::executor_type
5156{
52- test_context * ctx_;
57+ bench_io_context * ctx_;
5358
5459public:
55- explicit test_executor (test_context & ctx) noexcept
60+ explicit executor_type (bench_io_context & ctx) noexcept
5661 : ctx_(&ctx)
5762 {
5863 }
5964
60- test_context & context () const noexcept
65+ bench_io_context & context () const noexcept
6166 {
6267 return *ctx_;
6368 }
6469
65- bool operator ==(test_executor const & other) const noexcept
70+ bool operator ==(executor_type const & other) const noexcept
6671 {
6772 return ctx_ == other.ctx_ ;
6873 }
@@ -93,6 +98,15 @@ class test_executor
9398 }
9499};
95100
101+ inline bench_io_context::executor_type
102+ bench_io_context::get_executor () noexcept
103+ {
104+ return executor_type (*this );
105+ }
106+
107+ static_assert (Executor<bench_io_context::executor_type>);
108+ static_assert (ExecutionContext<bench_io_context>);
109+
96110// -----------------------------------------------
97111//
98112// Foreign Awaitable
@@ -251,14 +265,14 @@ int main()
251265{
252266 constexpr std::size_t iterations = 1000000 ;
253267
254- test_context ctx1;
255- test_context ctx2;
268+ bench_io_context ctx1;
269+ bench_io_context ctx2;
256270
257- test_executor ex1 ( ctx1);
258- test_executor ex2 ( ctx2);
271+ auto ex1 = ctx1. get_executor ( );
272+ auto ex2 = ctx2. get_executor ( );
259273
260- strand<test_executor > strand1 (ex1);
261- strand<test_executor > strand2 (ex2);
274+ strand<bench_io_context::executor_type > strand1 (ex1);
275+ strand<bench_io_context::executor_type > strand2 (ex2);
262276
263277 foreign_awaitable foreign;
264278
0 commit comments