diff options
| author | 2021-03-07 13:46:53 -0800 | |
|---|---|---|
| committer | 2021-03-07 13:46:53 -0800 | |
| commit | 8f7eb194af199ef7a3b225399e8d6fede27234f2 (patch) | |
| tree | 5b4bc3648e7dc9abf39312cb62e55e8feba92ae1 /src/common/fiber.cpp | |
| parent | common: fiber: Use weak_ptr when yielding. (diff) | |
| download | yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.gz yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.xz yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.zip | |
common: Fiber: use a reference for YieldTo.
- Fixes another small leak.
Diffstat (limited to 'src/common/fiber.cpp')
| -rw-r--r-- | src/common/fiber.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
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() { | |||
| 116 | boost::context::detail::jump_fcontext(impl->rewind_context, this); | 116 | boost::context::detail::jump_fcontext(impl->rewind_context, this); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | void Fiber::YieldTo(std::weak_ptr<Fiber> weak_from, std::shared_ptr<Fiber> to) { | 119 | void Fiber::YieldTo(std::weak_ptr<Fiber> weak_from, Fiber& to) { |
| 120 | ASSERT_MSG(to != nullptr, "Next fiber is null!"); | 120 | to.impl->guard.lock(); |
| 121 | to.impl->previous_fiber = weak_from.lock(); | ||
| 121 | 122 | ||
| 122 | to->impl->guard.lock(); | 123 | auto transfer = boost::context::detail::jump_fcontext(to.impl->context, &to); |
| 123 | to->impl->previous_fiber = weak_from.lock(); | ||
| 124 | |||
| 125 | auto transfer = boost::context::detail::jump_fcontext(to->impl->context, to.get()); | ||
| 126 | 124 | ||
| 127 | // "from" might no longer be valid if the thread was killed | 125 | // "from" might no longer be valid if the thread was killed |
| 128 | if (auto from = weak_from.lock(); from != nullptr) { | 126 | if (auto from = weak_from.lock()) { |
| 129 | ASSERT(from->impl->previous_fiber != nullptr); | 127 | ASSERT(from->impl->previous_fiber != nullptr); |
| 130 | from->impl->previous_fiber->impl->context = transfer.fctx; | 128 | from->impl->previous_fiber->impl->context = transfer.fctx; |
| 131 | from->impl->previous_fiber->impl->guard.unlock(); | 129 | from->impl->previous_fiber->impl->guard.unlock(); |