Implemented rewindless Fiber without Boost (using minicoro)

This commit is contained in:
darktux 2024-04-05 01:58:30 +02:00 committed by Briar
parent 60643dd1b2
commit 16f92e5b32
9 changed files with 2119 additions and 157 deletions

View file

@ -6,9 +6,7 @@
#include <functional>
#include <memory>
namespace boost::context::detail {
struct transfer_t;
}
#include "common/minicoro.h"
namespace Common {
@ -38,25 +36,18 @@ public:
Fiber(Fiber&&) = default;
Fiber& operator=(Fiber&&) = default;
/// 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, Fiber& to);
[[nodiscard]] static std::shared_ptr<Fiber> ThreadToFiber();
void SetRewindPoint(std::function<void()>&& rewind_func);
void Rewind();
/// Only call from main thread's fiber
void Exit();
private:
Fiber();
void OnRewind(boost::context::detail::transfer_t& transfer);
void Start(boost::context::detail::transfer_t& transfer);
static void FiberStartFunc(boost::context::detail::transfer_t transfer);
static void RewindStartFunc(boost::context::detail::transfer_t transfer);
void DestroyPre();
void DestroyWorkFiber();
void DestroyThreadFiber();
struct FiberImpl;
std::unique_ptr<FiberImpl> impl;