diff options
| author | 2022-07-05 18:20:39 -0400 | |
|---|---|---|
| committer | 2022-07-05 18:20:39 -0400 | |
| commit | 07e3c56f0de7a1567b1ae443abb64b767a31ed8c (patch) | |
| tree | 3bd7d56181d79c69988d3f6d1310d9137cbb482f /src/common/fiber.cpp | |
| parent | Merge pull request #8477 from Docteh/less_global (diff) | |
| parent | common/fiber: make fibers easier to use (diff) | |
| download | yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.gz yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.tar.xz yuzu-07e3c56f0de7a1567b1ae443abb64b767a31ed8c.zip | |
Merge pull request #8532 from liamwhite/fiber-supplements
common/fiber: make fibers easier to use
Diffstat (limited to 'src/common/fiber.cpp')
| -rw-r--r-- | src/common/fiber.cpp | 21 |
1 files changed, 6 insertions, 15 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 { | |||
| 20 | VirtualBuffer<u8> rewind_stack; | 20 | VirtualBuffer<u8> rewind_stack; |
| 21 | 21 | ||
| 22 | std::mutex guard; | 22 | std::mutex guard; |
| 23 | std::function<void(void*)> entry_point; | 23 | std::function<void()> entry_point; |
| 24 | std::function<void(void*)> rewind_point; | 24 | std::function<void()> rewind_point; |
| 25 | void* rewind_parameter{}; | ||
| 26 | void* start_parameter{}; | ||
| 27 | std::shared_ptr<Fiber> previous_fiber; | 25 | std::shared_ptr<Fiber> previous_fiber; |
| 28 | bool is_thread_fiber{}; | 26 | bool is_thread_fiber{}; |
| 29 | bool released{}; | 27 | bool released{}; |
| @@ -34,13 +32,8 @@ struct Fiber::FiberImpl { | |||
| 34 | boost::context::detail::fcontext_t rewind_context{}; | 32 | boost::context::detail::fcontext_t rewind_context{}; |
| 35 | }; | 33 | }; |
| 36 | 34 | ||
| 37 | void Fiber::SetStartParameter(void* new_parameter) { | 35 | void Fiber::SetRewindPoint(std::function<void()>&& rewind_func) { |
| 38 | impl->start_parameter = new_parameter; | ||
| 39 | } | ||
| 40 | |||
| 41 | void Fiber::SetRewindPoint(std::function<void(void*)>&& rewind_func, void* rewind_param) { | ||
| 42 | impl->rewind_point = std::move(rewind_func); | 36 | impl->rewind_point = std::move(rewind_func); |
| 43 | impl->rewind_parameter = rewind_param; | ||
| 44 | } | 37 | } |
| 45 | 38 | ||
| 46 | void Fiber::Start(boost::context::detail::transfer_t& transfer) { | 39 | void Fiber::Start(boost::context::detail::transfer_t& transfer) { |
| @@ -48,7 +41,7 @@ void Fiber::Start(boost::context::detail::transfer_t& transfer) { | |||
| 48 | impl->previous_fiber->impl->context = transfer.fctx; | 41 | impl->previous_fiber->impl->context = transfer.fctx; |
| 49 | impl->previous_fiber->impl->guard.unlock(); | 42 | impl->previous_fiber->impl->guard.unlock(); |
| 50 | impl->previous_fiber.reset(); | 43 | impl->previous_fiber.reset(); |
| 51 | impl->entry_point(impl->start_parameter); | 44 | impl->entry_point(); |
| 52 | UNREACHABLE(); | 45 | UNREACHABLE(); |
| 53 | } | 46 | } |
| 54 | 47 | ||
| @@ -59,7 +52,7 @@ void Fiber::OnRewind([[maybe_unused]] boost::context::detail::transfer_t& transf | |||
| 59 | u8* tmp = impl->stack_limit; | 52 | u8* tmp = impl->stack_limit; |
| 60 | impl->stack_limit = impl->rewind_stack_limit; | 53 | impl->stack_limit = impl->rewind_stack_limit; |
| 61 | impl->rewind_stack_limit = tmp; | 54 | impl->rewind_stack_limit = tmp; |
| 62 | impl->rewind_point(impl->rewind_parameter); | 55 | impl->rewind_point(); |
| 63 | UNREACHABLE(); | 56 | UNREACHABLE(); |
| 64 | } | 57 | } |
| 65 | 58 | ||
| @@ -73,10 +66,8 @@ void Fiber::RewindStartFunc(boost::context::detail::transfer_t transfer) { | |||
| 73 | fiber->OnRewind(transfer); | 66 | fiber->OnRewind(transfer); |
| 74 | } | 67 | } |
| 75 | 68 | ||
| 76 | Fiber::Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter) | 69 | Fiber::Fiber(std::function<void()>&& entry_point_func) : impl{std::make_unique<FiberImpl>()} { |
| 77 | : impl{std::make_unique<FiberImpl>()} { | ||
| 78 | impl->entry_point = std::move(entry_point_func); | 70 | impl->entry_point = std::move(entry_point_func); |
| 79 | impl->start_parameter = start_parameter; | ||
| 80 | impl->stack_limit = impl->stack.data(); | 71 | impl->stack_limit = impl->stack.data(); |
| 81 | impl->rewind_stack_limit = impl->rewind_stack.data(); | 72 | impl->rewind_stack_limit = impl->rewind_stack.data(); |
| 82 | u8* stack_base = impl->stack_limit + default_stack_size; | 73 | u8* stack_base = impl->stack_limit + default_stack_size; |