|
|
@ -17,10 +17,10 @@ namespace Common { |
|
|
constexpr std::size_t default_stack_size = 512 * 1024; |
|
|
constexpr std::size_t default_stack_size = 512 * 1024; |
|
|
|
|
|
|
|
|
struct Fiber::FiberImpl { |
|
|
struct Fiber::FiberImpl { |
|
|
FiberImpl() : stack{default_stack_size}, rewind_stack{default_stack_size} {} |
|
|
|
|
|
|
|
|
FiberImpl() : stack(default_stack_size), rewind_stack(default_stack_size) {} |
|
|
|
|
|
|
|
|
VirtualBuffer<u8> stack; |
|
|
|
|
|
VirtualBuffer<u8> rewind_stack; |
|
|
|
|
|
|
|
|
std::vector<u8> stack; |
|
|
|
|
|
std::vector<u8> rewind_stack; |
|
|
|
|
|
|
|
|
std::mutex guard; |
|
|
std::mutex guard; |
|
|
std::function<void()> entry_point; |
|
|
std::function<void()> entry_point; |
|
|
@ -105,8 +105,7 @@ void Fiber::Rewind() { |
|
|
ASSERT(impl->rewind_point); |
|
|
ASSERT(impl->rewind_point); |
|
|
ASSERT(impl->rewind_context == nullptr); |
|
|
ASSERT(impl->rewind_context == nullptr); |
|
|
u8* stack_base = impl->rewind_stack_limit + default_stack_size; |
|
|
u8* stack_base = impl->rewind_stack_limit + default_stack_size; |
|
|
impl->rewind_context = |
|
|
|
|
|
boost::context::detail::make_fcontext(stack_base, impl->stack.size(), RewindStartFunc); |
|
|
|
|
|
|
|
|
impl->rewind_context = boost::context::detail::make_fcontext(stack_base, impl->stack.size(), RewindStartFunc); |
|
|
boost::context::detail::jump_fcontext(impl->rewind_context, this); |
|
|
boost::context::detail::jump_fcontext(impl->rewind_context, this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -119,7 +118,7 @@ void Fiber::YieldTo(std::weak_ptr<Fiber> weak_from, Fiber& to) { |
|
|
// "from" might no longer be valid if the thread was killed
|
|
|
// "from" might no longer be valid if the thread was killed
|
|
|
if (auto from = weak_from.lock()) { |
|
|
if (auto from = weak_from.lock()) { |
|
|
if (from->impl->previous_fiber == nullptr) { |
|
|
if (from->impl->previous_fiber == nullptr) { |
|
|
ASSERT_MSG(false, "previous_fiber is nullptr!"); |
|
|
|
|
|
|
|
|
ASSERT(false && "previous_fiber is nullptr!"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
from->impl->previous_fiber->impl->context = transfer.fctx; |
|
|
from->impl->previous_fiber->impl->context = transfer.fctx; |
|
|
|