From d4ee14fe8f96789e9ea85624f4f83e9840be4fdb Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sat, 6 Mar 2021 08:01:53 +0100 Subject: [PATCH] early-access version 1505 --- README.md | 2 +- src/common/fiber.cpp | 19 ++++++++++++------- src/common/fiber.h | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e10a0d645..6bd5083c7 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1504. +This is the source code for early-access 1505. ## Legal Notice diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index 3c1eefcb7..b06fdc258 100755 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -116,16 +116,21 @@ void Fiber::Rewind() { boost::context::detail::jump_fcontext(impl->rewind_context, this); } -void Fiber::YieldTo(std::shared_ptr from, std::shared_ptr to) { - ASSERT_MSG(from != nullptr, "Yielding fiber is null!"); +void Fiber::YieldTo(std::weak_ptr weak_from, std::shared_ptr to) { ASSERT_MSG(to != nullptr, "Next fiber is null!"); + to->impl->guard.lock(); - to->impl->previous_fiber = from; + to->impl->previous_fiber = weak_from.lock(); + 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.reset(); + + // "from" might no longer be valid if the thread was killed + if (auto from = weak_from.lock(); from != nullptr) { + 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.reset(); + } } std::shared_ptr Fiber::ThreadToFiber() { diff --git a/src/common/fiber.h b/src/common/fiber.h index f7f587f8c..d96be6019 100755 --- a/src/common/fiber.h +++ b/src/common/fiber.h @@ -41,7 +41,7 @@ public: /// Yields control from Fiber 'from' to Fiber 'to' /// Fiber 'from' must be the currently running fiber. - static void YieldTo(std::shared_ptr from, std::shared_ptr to); + static void YieldTo(std::weak_ptr weak_from, std::shared_ptr to); [[nodiscard]] static std::shared_ptr ThreadToFiber(); void SetRewindPoint(std::function&& rewind_func, void* rewind_param);