diff options
Diffstat (limited to 'src/common/fiber.cpp')
| -rw-r--r-- | src/common/fiber.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index b8e98b12a..3c1eefcb7 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp | |||
| @@ -24,7 +24,7 @@ struct Fiber::FiberImpl { | |||
| 24 | std::function<void(void*)> rewind_point; | 24 | std::function<void(void*)> rewind_point; |
| 25 | void* rewind_parameter{}; | 25 | void* rewind_parameter{}; |
| 26 | void* start_parameter{}; | 26 | void* start_parameter{}; |
| 27 | Fiber* previous_fiber; | 27 | std::shared_ptr<Fiber> previous_fiber; |
| 28 | bool is_thread_fiber{}; | 28 | bool is_thread_fiber{}; |
| 29 | bool released{}; | 29 | bool released{}; |
| 30 | 30 | ||
| @@ -47,7 +47,7 @@ void Fiber::Start(boost::context::detail::transfer_t& transfer) { | |||
| 47 | ASSERT(impl->previous_fiber != nullptr); | 47 | ASSERT(impl->previous_fiber != nullptr); |
| 48 | impl->previous_fiber->impl->context = transfer.fctx; | 48 | impl->previous_fiber->impl->context = transfer.fctx; |
| 49 | impl->previous_fiber->impl->guard.unlock(); | 49 | impl->previous_fiber->impl->guard.unlock(); |
| 50 | impl->previous_fiber = nullptr; | 50 | impl->previous_fiber.reset(); |
| 51 | impl->entry_point(impl->start_parameter); | 51 | impl->entry_point(impl->start_parameter); |
| 52 | UNREACHABLE(); | 52 | UNREACHABLE(); |
| 53 | } | 53 | } |
| @@ -116,20 +116,20 @@ 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(Fiber* from, Fiber* to) { | 119 | void Fiber::YieldTo(std::shared_ptr<Fiber> from, std::shared_ptr<Fiber> to) { |
| 120 | ASSERT_MSG(from != nullptr, "Yielding fiber is null!"); | 120 | ASSERT_MSG(from != nullptr, "Yielding fiber is null!"); |
| 121 | ASSERT_MSG(to != nullptr, "Next fiber is null!"); | 121 | ASSERT_MSG(to != nullptr, "Next fiber is null!"); |
| 122 | to->impl->guard.lock(); | 122 | to->impl->guard.lock(); |
| 123 | to->impl->previous_fiber = from; | 123 | to->impl->previous_fiber = from; |
| 124 | auto transfer = boost::context::detail::jump_fcontext(to->impl->context, to); | 124 | auto transfer = boost::context::detail::jump_fcontext(to->impl->context, to.get()); |
| 125 | ASSERT(from->impl->previous_fiber != nullptr); | 125 | ASSERT(from->impl->previous_fiber != nullptr); |
| 126 | from->impl->previous_fiber->impl->context = transfer.fctx; | 126 | from->impl->previous_fiber->impl->context = transfer.fctx; |
| 127 | from->impl->previous_fiber->impl->guard.unlock(); | 127 | from->impl->previous_fiber->impl->guard.unlock(); |
| 128 | from->impl->previous_fiber = nullptr; | 128 | from->impl->previous_fiber.reset(); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | std::unique_ptr<Fiber> Fiber::ThreadToFiber() { | 131 | std::shared_ptr<Fiber> Fiber::ThreadToFiber() { |
| 132 | std::unique_ptr<Fiber> fiber = std::unique_ptr<Fiber>{new Fiber()}; | 132 | std::shared_ptr<Fiber> fiber = std::shared_ptr<Fiber>{new Fiber()}; |
| 133 | fiber->impl->guard.lock(); | 133 | fiber->impl->guard.lock(); |
| 134 | fiber->impl->is_thread_fiber = true; | 134 | fiber->impl->is_thread_fiber = true; |
| 135 | return fiber; | 135 | return fiber; |