diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2022-07-06 00:20:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-06 00:20:39 +0200 |
commit | 07e3c56f0de7a1567b1ae443abb64b767a31ed8c (patch) | |
tree | 3bd7d56181d79c69988d3f6d1310d9137cbb482f /src/common | |
parent | Merge pull request #8477 from Docteh/less_global (diff) | |
parent | common/fiber: make fibers easier to use (diff) | |
download | yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.gz yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.bz2 yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.lz yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.xz yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.zst yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/fiber.cpp | 21 | ||||
-rw-r--r-- | src/common/fiber.h | 7 |
2 files changed, 8 insertions, 20 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index f9aeb692a..bc92b360b 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -20,10 +20,8 @@ struct Fiber::FiberImpl { VirtualBuffer<u8> rewind_stack; std::mutex guard; - std::function<void(void*)> entry_point; - std::function<void(void*)> rewind_point; - void* rewind_parameter{}; - void* start_parameter{}; + std::function<void()> entry_point; + std::function<void()> rewind_point; std::shared_ptr<Fiber> previous_fiber; bool is_thread_fiber{}; bool released{}; @@ -34,13 +32,8 @@ struct Fiber::FiberImpl { boost::context::detail::fcontext_t rewind_context{}; }; -void Fiber::SetStartParameter(void* new_parameter) { - impl->start_parameter = new_parameter; -} - -void Fiber::SetRewindPoint(std::function<void(void*)>&& rewind_func, void* rewind_param) { +void Fiber::SetRewindPoint(std::function<void()>&& rewind_func) { impl->rewind_point = std::move(rewind_func); - impl->rewind_parameter = rewind_param; } void Fiber::Start(boost::context::detail::transfer_t& transfer) { @@ -48,7 +41,7 @@ void Fiber::Start(boost::context::detail::transfer_t& transfer) { impl->previous_fiber->impl->context = transfer.fctx; impl->previous_fiber->impl->guard.unlock(); impl->previous_fiber.reset(); - impl->entry_point(impl->start_parameter); + impl->entry_point(); UNREACHABLE(); } @@ -59,7 +52,7 @@ void Fiber::OnRewind([[maybe_unused]] boost::context::detail::transfer_t& transf u8* tmp = impl->stack_limit; impl->stack_limit = impl->rewind_stack_limit; impl->rewind_stack_limit = tmp; - impl->rewind_point(impl->rewind_parameter); + impl->rewind_point(); UNREACHABLE(); } @@ -73,10 +66,8 @@ void Fiber::RewindStartFunc(boost::context::detail::transfer_t transfer) { fiber->OnRewind(transfer); } -Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) - : impl{std::make_unique<FiberImpl>()} { +Fiber::Fiber(std::function<void()>&& entry_point_func) : impl{std::make_unique<FiberImpl>()} { impl->entry_point = std::move(entry_point_func); - impl->start_parameter = start_parameter; impl->stack_limit = impl->stack.data(); impl->rewind_stack_limit = impl->rewind_stack.data(); u8* stack_base = impl->stack_limit + default_stack_size; diff --git a/src/common/fiber.h b/src/common/fiber.h index 873604bc6..f24d333a3 100644 --- a/src/common/fiber.h +++ b/src/common/fiber.h @@ -29,7 +29,7 @@ namespace Common { */ class Fiber { public: - Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter); + Fiber(std::function<void()>&& entry_point_func); ~Fiber(); Fiber(const Fiber&) = delete; @@ -43,16 +43,13 @@ public: 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); + void SetRewindPoint(std::function<void()>&& rewind_func); void Rewind(); /// Only call from main thread's fiber void Exit(); - /// Changes the start parameter of the fiber. Has no effect if the fiber already started - void SetStartParameter(void* new_parameter); - private: Fiber(); |