From 8f7eb194af199ef7a3b225399e8d6fede27234f2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 7 Mar 2021 13:46:53 -0800 Subject: common: Fiber: use a reference for YieldTo. - Fixes another small leak. --- src/common/fiber.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/common/fiber.cpp') diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index b06fdc258..39532ff58 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -116,16 +116,14 @@ void Fiber::Rewind() { boost::context::detail::jump_fcontext(impl->rewind_context, this); } -void Fiber::YieldTo(std::weak_ptr weak_from, std::shared_ptr to) { - ASSERT_MSG(to != nullptr, "Next fiber is null!"); +void Fiber::YieldTo(std::weak_ptr weak_from, Fiber& to) { + to.impl->guard.lock(); + to.impl->previous_fiber = weak_from.lock(); - to->impl->guard.lock(); - to->impl->previous_fiber = weak_from.lock(); - - auto transfer = boost::context::detail::jump_fcontext(to->impl->context, to.get()); + auto transfer = boost::context::detail::jump_fcontext(to.impl->context, &to); // "from" might no longer be valid if the thread was killed - if (auto from = weak_from.lock(); from != nullptr) { + if (auto from = weak_from.lock()) { ASSERT(from->impl->previous_fiber != nullptr); from->impl->previous_fiber->impl->context = transfer.fctx; from->impl->previous_fiber->impl->guard.unlock(); -- cgit v1.2.3