@@ -46,6 +46,62 @@ struct linear_allocator {
4646
4747static_assert (lf::stack_allocator<linear_allocator>);
4848
49+ template <lf::stack_allocator Alloc>
50+ struct vector_ctx {
51+
52+ using handle_type = lf::frame_handle<vector_ctx>;
53+
54+ std::vector<handle_type> work;
55+ Alloc allocator;
56+
57+ vector_ctx () { work.reserve (1024 ); }
58+
59+ auto alloc () noexcept -> Alloc & { return allocator; }
60+
61+ // TODO: try LF_NO_INLINE for final allocator
62+ LF_NO_INLINE
63+ void push (handle_type handle) { work.push_back (handle); }
64+
65+ auto pop () noexcept -> handle_type {
66+ auto handle = work.back ();
67+ work.pop_back ();
68+ return handle;
69+ }
70+ };
71+
72+ template <lf::stack_allocator Alloc>
73+ struct poly_vector_ctx final : lf::polymorphic_context<Alloc> {
74+
75+ using handle_type = lf::frame_handle<lf::polymorphic_context<Alloc>>;
76+
77+ std::vector<handle_type> work;
78+
79+ poly_vector_ctx () { work.reserve (1024 ); }
80+
81+ void push (handle_type handle) override { work.push_back (handle); }
82+
83+ auto pop () noexcept -> handle_type override {
84+ auto handle = work.back ();
85+ work.pop_back ();
86+ return handle;
87+ }
88+ };
89+
90+ struct poly_deque_ctx final : lf::polymorphic_context<linear_allocator> {
91+
92+ using handle_type = lf::frame_handle<lf::polymorphic_context<linear_allocator>>;
93+
94+ lf::deque<handle_type> work;
95+
96+ void push (handle_type handle) override { work.push (handle); }
97+
98+ auto pop () noexcept -> handle_type override {
99+ return work.pop ([] static -> handle_type {
100+ return {};
101+ });
102+ }
103+ };
104+
49105using lf::task;
50106
51107template <lf::worker_context T>
@@ -217,3 +273,12 @@ BENCHMARK(fib<fork_call<B>, A, B>)->Name("base/libfork/fib/poly_vector_ctx")->Ar
217273// Same as above but with join.
218274BENCHMARK (fib<fork_call<B, true >, A, B>)->Name(" test/libfork/fib/poly_vector_ctx/join" )->Arg(fib_test);
219275BENCHMARK (fib<fork_call<B, true >, A, B>)->Name(" base/libfork/fib/poly_vector_ctx/join" )->Arg(fib_base);
276+
277+ using C = poly_deque_ctx;
278+
279+ // Return by value,
280+ // Libfork call/join/fork with co-await,
281+ // Polymorphic
282+ // Deque-backed context
283+ BENCHMARK (fib<fork_call<B, true >, C, B>)->Name(" test/libfork/fib/poly_deque_ctx/join" )->Arg(fib_test);
284+ BENCHMARK (fib<fork_call<B, true >, C, B>)->Name(" base/libfork/fib/poly_deque_ctx/join" )->Arg(fib_base);
0 commit comments