From a5ab85ac37bbfed739e75ba9c2226b1e6bf1fd37 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 5 Mar 2021 17:08:17 -0800 Subject: Revert "core: Switch to unique_ptr for usage of Common::Fiber." --- src/common/fiber.cpp | 14 +++++++------- src/common/fiber.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/common') diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index b8e98b12a..3c1eefcb7 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -24,7 +24,7 @@ struct Fiber::FiberImpl { std::function rewind_point; void* rewind_parameter{}; void* start_parameter{}; - Fiber* previous_fiber; + std::shared_ptr previous_fiber; bool is_thread_fiber{}; bool released{}; @@ -47,7 +47,7 @@ void Fiber::Start(boost::context::detail::transfer_t& transfer) { ASSERT(impl->previous_fiber != nullptr); impl->previous_fiber->impl->context = transfer.fctx; impl->previous_fiber->impl->guard.unlock(); - impl->previous_fiber = nullptr; + impl->previous_fiber.reset(); impl->entry_point(impl->start_parameter); UNREACHABLE(); } @@ -116,20 +116,20 @@ void Fiber::Rewind() { boost::context::detail::jump_fcontext(impl->rewind_context, this); } -void Fiber::YieldTo(Fiber* from, Fiber* to) { +void Fiber::YieldTo(std::shared_ptr from, std::shared_ptr to) { ASSERT_MSG(from != nullptr, "Yielding fiber is null!"); ASSERT_MSG(to != nullptr, "Next fiber is null!"); to->impl->guard.lock(); to->impl->previous_fiber = from; - auto transfer = boost::context::detail::jump_fcontext(to->impl->context, to); + auto transfer = boost::context::detail::jump_fcontext(to->impl->context, to.get()); ASSERT(from->impl->previous_fiber != nullptr); from->impl->previous_fiber->impl->context = transfer.fctx; from->impl->previous_fiber->impl->guard.unlock(); - from->impl->previous_fiber = nullptr; + from->impl->previous_fiber.reset(); } -std::unique_ptr Fiber::ThreadToFiber() { - std::unique_ptr fiber = std::unique_ptr{new Fiber()}; +std::shared_ptr Fiber::ThreadToFiber() { + std::shared_ptr fiber = std::shared_ptr{new Fiber()}; fiber->impl->guard.lock(); fiber->impl->is_thread_fiber = true; return fiber; diff --git a/src/common/fiber.h b/src/common/fiber.h index 6924f7996..f7f587f8c 100644 --- a/src/common/fiber.h +++ b/src/common/fiber.h @@ -41,8 +41,8 @@ public: /// Yields control from Fiber 'from' to Fiber 'to' /// Fiber 'from' must be the currently running fiber. - static void YieldTo(Fiber* from, Fiber* to); - [[nodiscard]] static std::unique_ptr ThreadToFiber(); + static void YieldTo(std::shared_ptr from, std::shared_ptr to); + [[nodiscard]] static std::shared_ptr ThreadToFiber(); void SetRewindPoint(std::function&& rewind_func, void* rewind_param); -- cgit v1.2.3