summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-03-07 22:46:53 +0100
committerbunnei <bunneidev@gmail.com>2021-03-07 22:46:53 +0100
commit8f7eb194af199ef7a3b225399e8d6fede27234f2 (patch)
tree5b4bc3648e7dc9abf39312cb62e55e8feba92ae1 /src/common
parentcommon: fiber: Use weak_ptr when yielding. (diff)
downloadyuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar
yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.gz
yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.bz2
yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.lz
yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.xz
yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.tar.zst
yuzu-8f7eb194af199ef7a3b225399e8d6fede27234f2.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fiber.cpp12
-rw-r--r--src/common/fiber.h2
2 files changed, 6 insertions, 8 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() {
boost::context::detail::jump_fcontext(impl->rewind_context, this);
}
-void Fiber::YieldTo(std::weak_ptr<Fiber> weak_from, std::shared_ptr<Fiber> to) {
- ASSERT_MSG(to != nullptr, "Next fiber is null!");
+void Fiber::YieldTo(std::weak_ptr<Fiber> 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();
diff --git a/src/common/fiber.h b/src/common/fiber.h
index d96be6019..f2a8ff29a 100644
--- 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::weak_ptr<Fiber> weak_from, std::shared_ptr<Fiber> to);
+ static void YieldTo(std::weak_ptr<Fiber> weak_from, Fiber& to);
[[nodiscard]] static std::shared_ptr<Fiber> ThreadToFiber();
void SetRewindPoint(std::function<void(void*)>&& rewind_func, void* rewind_param);