diff options
Diffstat (limited to 'src/common/fiber.h')
| -rw-r--r-- | src/common/fiber.h | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/src/common/fiber.h b/src/common/fiber.h index 89dde5e36..f7f587f8c 100644 --- a/src/common/fiber.h +++ b/src/common/fiber.h | |||
| @@ -7,14 +7,9 @@ | |||
| 7 | #include <functional> | 7 | #include <functional> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | 9 | ||
| 10 | #include "common/common_types.h" | ||
| 11 | #include "common/spin_lock.h" | ||
| 12 | |||
| 13 | #if !defined(_WIN32) && !defined(WIN32) | ||
| 14 | namespace boost::context::detail { | 10 | namespace boost::context::detail { |
| 15 | struct transfer_t; | 11 | struct transfer_t; |
| 16 | } | 12 | } |
| 17 | #endif | ||
| 18 | 13 | ||
| 19 | namespace Common { | 14 | namespace Common { |
| 20 | 15 | ||
| @@ -46,10 +41,10 @@ public: | |||
| 46 | 41 | ||
| 47 | /// Yields control from Fiber 'from' to Fiber 'to' | 42 | /// Yields control from Fiber 'from' to Fiber 'to' |
| 48 | /// Fiber 'from' must be the currently running fiber. | 43 | /// Fiber 'from' must be the currently running fiber. |
| 49 | static void YieldTo(std::shared_ptr<Fiber>& from, std::shared_ptr<Fiber>& to); | 44 | static void YieldTo(std::shared_ptr<Fiber> from, std::shared_ptr<Fiber> to); |
| 50 | [[nodiscard]] static std::shared_ptr<Fiber> ThreadToFiber(); | 45 | [[nodiscard]] static std::shared_ptr<Fiber> ThreadToFiber(); |
| 51 | 46 | ||
| 52 | void SetRewindPoint(std::function<void(void*)>&& rewind_func, void* start_parameter); | 47 | void SetRewindPoint(std::function<void(void*)>&& rewind_func, void* rewind_param); |
| 53 | 48 | ||
| 54 | void Rewind(); | 49 | void Rewind(); |
| 55 | 50 | ||
| @@ -57,36 +52,18 @@ public: | |||
| 57 | void Exit(); | 52 | void Exit(); |
| 58 | 53 | ||
| 59 | /// Changes the start parameter of the fiber. Has no effect if the fiber already started | 54 | /// Changes the start parameter of the fiber. Has no effect if the fiber already started |
| 60 | void SetStartParameter(void* new_parameter) { | 55 | void SetStartParameter(void* new_parameter); |
| 61 | start_parameter = new_parameter; | ||
| 62 | } | ||
| 63 | 56 | ||
| 64 | private: | 57 | private: |
| 65 | Fiber(); | 58 | Fiber(); |
| 66 | 59 | ||
| 67 | #if defined(_WIN32) || defined(WIN32) | ||
| 68 | void OnRewind(); | ||
| 69 | void Start(); | ||
| 70 | static void FiberStartFunc(void* fiber_parameter); | ||
| 71 | static void RewindStartFunc(void* fiber_parameter); | ||
| 72 | #else | ||
| 73 | void OnRewind(boost::context::detail::transfer_t& transfer); | 60 | void OnRewind(boost::context::detail::transfer_t& transfer); |
| 74 | void Start(boost::context::detail::transfer_t& transfer); | 61 | void Start(boost::context::detail::transfer_t& transfer); |
| 75 | static void FiberStartFunc(boost::context::detail::transfer_t transfer); | 62 | static void FiberStartFunc(boost::context::detail::transfer_t transfer); |
| 76 | static void RewindStartFunc(boost::context::detail::transfer_t transfer); | 63 | static void RewindStartFunc(boost::context::detail::transfer_t transfer); |
| 77 | #endif | ||
| 78 | 64 | ||
| 79 | struct FiberImpl; | 65 | struct FiberImpl; |
| 80 | |||
| 81 | SpinLock guard{}; | ||
| 82 | std::function<void(void*)> entry_point; | ||
| 83 | std::function<void(void*)> rewind_point; | ||
| 84 | void* rewind_parameter{}; | ||
| 85 | void* start_parameter{}; | ||
| 86 | std::shared_ptr<Fiber> previous_fiber; | ||
| 87 | std::unique_ptr<FiberImpl> impl; | 66 | std::unique_ptr<FiberImpl> impl; |
| 88 | bool is_thread_fiber{}; | ||
| 89 | bool released{}; | ||
| 90 | }; | 67 | }; |
| 91 | 68 | ||
| 92 | } // namespace Common | 69 | } // namespace Common |