From ed0319cfed2c99e6366aaf725d96bb28a9332e4d Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 2 Jul 2022 12:33:49 -0400 Subject: common/fiber: make fibers easier to use --- src/common/fiber.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/common/fiber.cpp') diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index f9aeb692a..bc92b360b 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -20,10 +20,8 @@ struct Fiber::FiberImpl { VirtualBuffer rewind_stack; std::mutex guard; - std::function entry_point; - std::function rewind_point; - void* rewind_parameter{}; - void* start_parameter{}; + std::function entry_point; + std::function rewind_point; std::shared_ptr previous_fiber; bool is_thread_fiber{}; bool released{}; @@ -34,13 +32,8 @@ struct Fiber::FiberImpl { boost::context::detail::fcontext_t rewind_context{}; }; -void Fiber::SetStartParameter(void* new_parameter) { - impl->start_parameter = new_parameter; -} - -void Fiber::SetRewindPoint(std::function&& rewind_func, void* rewind_param) { +void Fiber::SetRewindPoint(std::function&& rewind_func) { impl->rewind_point = std::move(rewind_func); - impl->rewind_parameter = rewind_param; } void Fiber::Start(boost::context::detail::transfer_t& transfer) { @@ -48,7 +41,7 @@ void Fiber::Start(boost::context::detail::transfer_t& transfer) { impl->previous_fiber->impl->context = transfer.fctx; impl->previous_fiber->impl->guard.unlock(); impl->previous_fiber.reset(); - impl->entry_point(impl->start_parameter); + impl->entry_point(); UNREACHABLE(); } @@ -59,7 +52,7 @@ void Fiber::OnRewind([[maybe_unused]] boost::context::detail::transfer_t& transf u8* tmp = impl->stack_limit; impl->stack_limit = impl->rewind_stack_limit; impl->rewind_stack_limit = tmp; - impl->rewind_point(impl->rewind_parameter); + impl->rewind_point(); UNREACHABLE(); } @@ -73,10 +66,8 @@ void Fiber::RewindStartFunc(boost::context::detail::transfer_t transfer) { fiber->OnRewind(transfer); } -Fiber::Fiber(std::function&& entry_point_func, void* start_parameter) - : impl{std::make_unique()} { +Fiber::Fiber(std::function&& entry_point_func) : impl{std::make_unique()} { impl->entry_point = std::move(entry_point_func); - impl->start_parameter = start_parameter; impl->stack_limit = impl->stack.data(); impl->rewind_stack_limit = impl->rewind_stack.data(); u8* stack_base = impl->stack_limit + default_stack_size; -- cgit v1.2.3