summaryrefslogtreecommitdiffstats
path: root/src/common/fiber.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-03-06 07:10:03 +0100
committerbunnei <bunneidev@gmail.com>2021-03-06 07:10:03 +0100
commit68ffac250ae2d1c2d5d961304d2c61f6755ab033 (patch)
tree4888d0fd2474dc90ad84a17ba71010a325beb984 /src/common/fiber.cpp
parentMerge pull request #6036 from bunnei/thread-leak (diff)
downloadyuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.tar
yuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.tar.gz
yuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.tar.bz2
yuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.tar.lz
yuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.tar.xz
yuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.tar.zst
yuzu-68ffac250ae2d1c2d5d961304d2c61f6755ab033.zip
Diffstat (limited to 'src/common/fiber.cpp')
-rw-r--r--src/common/fiber.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp
index 3c1eefcb7..b06fdc258 100644
--- 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<Fiber> from, std::shared_ptr<Fiber> to) {
- ASSERT_MSG(from != nullptr, "Yielding fiber is null!");
+void Fiber::YieldTo(std::weak_ptr<Fiber> weak_from, std::shared_ptr<Fiber> 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> Fiber::ThreadToFiber() {