Commit 3433e03c authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Reverted commit D4035769

Summary: This diff adapts the fibers code to the modified `fcontext` API from Boost 1.61

Reviewed By: Orvid

Differential Revision: D4035769

fbshipit-source-id: d3f4b6b03efdd3b6e4b92e0e1c7373747bb74fbb
parent 81a037df
...@@ -15,13 +15,8 @@ ...@@ -15,13 +15,8 @@
*/ */
#pragma once #pragma once
#include <boost/version.hpp>
#if BOOST_VERSION >= 106100
#include <boost/context/detail/fcontext.hpp>
#else
#include <boost/context/fcontext.hpp> #include <boost/context/fcontext.hpp>
#endif #include <boost/version.hpp>
/** /**
* Wrappers for different versions of boost::context library * Wrappers for different versions of boost::context library
...@@ -39,28 +34,12 @@ namespace fibers { ...@@ -39,28 +34,12 @@ namespace fibers {
struct FContext { struct FContext {
public: public:
#if BOOST_VERSION >= 106100 #if BOOST_VERSION >= 105200
using ContextStruct = boost::context::detail::fcontext_t;
#elif BOOST_VERSION >= 105200
using ContextStruct = boost::context::fcontext_t; using ContextStruct = boost::context::fcontext_t;
#else #else
using ContextStruct = boost::ctx::fcontext_t; using ContextStruct = boost::ctx::fcontext_t;
#endif #endif
#if BOOST_VERSION >= 106100
using FiberArg = boost::context::detail::transfer_t;
using FiberData = void*;
static void* getFiber(FiberArg arg) {
return arg.fctx;
}
#else
using FiberArg = intptr_t;
using FiberData = intptr_t;
static FiberArg getFiber(FiberArg arg) {
return arg;
}
#endif
void* stackLimit() const { void* stackLimit() const {
return stackLimit_; return stackLimit_;
} }
...@@ -81,24 +60,17 @@ struct FContext { ...@@ -81,24 +60,17 @@ struct FContext {
ContextStruct context_; ContextStruct context_;
#endif #endif
friend FiberData friend intptr_t
jumpContext(FContext* oldC, FContext::ContextStruct* newC, FiberData p); jumpContext(FContext* oldC, FContext::ContextStruct* newC, intptr_t p);
friend FiberData friend intptr_t
jumpContext(FContext::ContextStruct* oldC, FContext* newC, FiberData p); jumpContext(FContext::ContextStruct* oldC, FContext* newC, intptr_t p);
friend FContext friend FContext
makeContext(void* stackLimit, size_t stackSize, void (*fn)(FiberArg)); makeContext(void* stackLimit, size_t stackSize, void (*fn)(intptr_t));
}; };
inline FContext::FiberData jumpContext( inline intptr_t
FContext* oldC, jumpContext(FContext* oldC, FContext::ContextStruct* newC, intptr_t p) {
FContext::ContextStruct* newC, #if BOOST_VERSION >= 105600
FContext::FiberData p) {
#if BOOST_VERSION >= 106100
boost::context::detail::transfer_t result =
boost::context::detail::jump_fcontext(*newC, p);
oldC->context_ = result.fctx;
return result.data;
#elif BOOST_VERSION >= 105600
return boost::context::jump_fcontext(&oldC->context_, *newC, p); return boost::context::jump_fcontext(&oldC->context_, *newC, p);
#elif BOOST_VERSION >= 105200 #elif BOOST_VERSION >= 105200
return boost::context::jump_fcontext(oldC->context_, newC, p); return boost::context::jump_fcontext(oldC->context_, newC, p);
...@@ -107,34 +79,22 @@ inline FContext::FiberData jumpContext( ...@@ -107,34 +79,22 @@ inline FContext::FiberData jumpContext(
#endif #endif
} }
inline FContext::FiberData jumpContext( inline intptr_t
FContext::ContextStruct* oldC, jumpContext(FContext::ContextStruct* oldC, FContext* newC, intptr_t p) {
FContext* newC, #if BOOST_VERSION >= 105200
FContext::FiberData p) {
#if BOOST_VERSION >= 106100
boost::context::detail::transfer_t result =
boost::context::detail::jump_fcontext(newC->context_, p);
*oldC = result.fctx;
return result.data;
#elif BOOST_VERSION >= 105200
return boost::context::jump_fcontext(oldC, newC->context_, p); return boost::context::jump_fcontext(oldC, newC->context_, p);
#else #else
return jump_fcontext(oldC, &newC->context_, p); return jump_fcontext(oldC, &newC->context_, p);
#endif #endif
} }
inline FContext makeContext( inline FContext
void* stackLimit, makeContext(void* stackLimit, size_t stackSize, void (*fn)(intptr_t)) {
size_t stackSize,
void (*fn)(FContext::FiberArg)) {
FContext res; FContext res;
res.stackLimit_ = stackLimit; res.stackLimit_ = stackLimit;
res.stackBase_ = static_cast<unsigned char*>(stackLimit) + stackSize; res.stackBase_ = static_cast<unsigned char*>(stackLimit) + stackSize;
#if BOOST_VERSION >= 106100 #if BOOST_VERSION >= 105200
res.context_ =
boost::context::detail::make_fcontext(res.stackBase_, stackSize, fn);
#elif BOOST_VERSION >= 105200
res.context_ = boost::context::make_fcontext(res.stackBase_, stackSize, fn); res.context_ = boost::context::make_fcontext(res.stackBase_, stackSize, fn);
#else #else
res.context_.fc_stack.limit = stackLimit; res.context_.fc_stack.limit = stackLimit;
......
...@@ -50,7 +50,7 @@ static size_t nonMagicInBytes(const FContext& context) { ...@@ -50,7 +50,7 @@ static size_t nonMagicInBytes(const FContext& context) {
} // anonymous namespace } // anonymous namespace
void Fiber::setData(FContext::FiberData data) { void Fiber::setData(intptr_t data) {
DCHECK_EQ(state_, AWAITING); DCHECK_EQ(state_, AWAITING);
data_ = data; data_ = data;
state_ = READY_TO_RUN; state_ = READY_TO_RUN;
...@@ -121,8 +121,8 @@ void Fiber::recordStackPosition() { ...@@ -121,8 +121,8 @@ void Fiber::recordStackPosition() {
VLOG(4) << "Stack usage: " << currentPosition; VLOG(4) << "Stack usage: " << currentPosition;
} }
void Fiber::fiberFuncHelper(FContext::FiberArg fiber) { void Fiber::fiberFuncHelper(intptr_t fiber) {
reinterpret_cast<Fiber*>(FContext::getFiber(fiber))->fiberFunc(); reinterpret_cast<Fiber*>(fiber)->fiberFunc();
} }
void Fiber::fiberFunc() { void Fiber::fiberFunc() {
...@@ -170,8 +170,8 @@ void Fiber::fiberFunc() { ...@@ -170,8 +170,8 @@ void Fiber::fiberFunc() {
} }
} }
FContext::FiberData Fiber::preempt(State state) { intptr_t Fiber::preempt(State state) {
FContext::FiberData ret; intptr_t ret;
auto preemptImpl = [&]() mutable { auto preemptImpl = [&]() mutable {
DCHECK_EQ(fiberManager_.activeFiber_, this); DCHECK_EQ(fiberManager_.activeFiber_, this);
......
...@@ -49,7 +49,7 @@ class Fiber { ...@@ -49,7 +49,7 @@ class Fiber {
* *
* @param data this data will be returned by await() when task is resumed. * @param data this data will be returned by await() when task is resumed.
*/ */
void setData(FContext::FiberData data); void setData(intptr_t data);
Fiber(const Fiber&) = delete; Fiber(const Fiber&) = delete;
Fiber& operator=(const Fiber&) = delete; Fiber& operator=(const Fiber&) = delete;
...@@ -97,7 +97,7 @@ class Fiber { ...@@ -97,7 +97,7 @@ class Fiber {
template <typename F, typename G> template <typename F, typename G>
void setFunctionFinally(F&& func, G&& finally); void setFunctionFinally(F&& func, G&& finally);
static void fiberFuncHelper(FContext::FiberArg fiber); static void fiberFuncHelper(intptr_t fiber);
void fiberFunc(); void fiberFunc();
/** /**
...@@ -108,7 +108,7 @@ class Fiber { ...@@ -108,7 +108,7 @@ class Fiber {
* *
* @return The value passed back from the main context. * @return The value passed back from the main context.
*/ */
FContext::FiberData preempt(State state); intptr_t preempt(State state);
/** /**
* Examines how much of the stack we used at this moment and * Examines how much of the stack we used at this moment and
...@@ -118,7 +118,7 @@ class Fiber { ...@@ -118,7 +118,7 @@ class Fiber {
FiberManager& fiberManager_; /**< Associated FiberManager */ FiberManager& fiberManager_; /**< Associated FiberManager */
FContext fcontext_; /**< current task execution context */ FContext fcontext_; /**< current task execution context */
FContext::FiberData data_; /**< Used to keep some data with the Fiber */ intptr_t data_; /**< Used to keep some data with the Fiber */
std::shared_ptr<RequestContext> rcontext_; /**< current RequestContext */ std::shared_ptr<RequestContext> rcontext_; /**< current RequestContext */
folly::Function<void()> func_; /**< task function */ folly::Function<void()> func_; /**< task function */
bool recordStackUsed_{false}; bool recordStackUsed_{false};
......
...@@ -58,7 +58,7 @@ inline void FiberManager::ensureLoopScheduled() { ...@@ -58,7 +58,7 @@ inline void FiberManager::ensureLoopScheduled() {
loopController_->schedule(); loopController_->schedule();
} }
inline FContext::FiberData FiberManager::activateFiber(Fiber* fiber) { inline intptr_t FiberManager::activateFiber(Fiber* fiber) {
DCHECK_EQ(activeFiber_, (Fiber*)nullptr); DCHECK_EQ(activeFiber_, (Fiber*)nullptr);
#ifdef FOLLY_SANITIZE_ADDRESS #ifdef FOLLY_SANITIZE_ADDRESS
...@@ -78,7 +78,7 @@ inline FContext::FiberData FiberManager::activateFiber(Fiber* fiber) { ...@@ -78,7 +78,7 @@ inline FContext::FiberData FiberManager::activateFiber(Fiber* fiber) {
return jumpContext(&mainContext_, &fiber->fcontext_, fiber->data_); return jumpContext(&mainContext_, &fiber->fcontext_, fiber->data_);
} }
inline FContext::FiberData FiberManager::deactivateFiber(Fiber* fiber) { inline intptr_t FiberManager::deactivateFiber(Fiber* fiber) {
DCHECK_EQ(activeFiber_, fiber); DCHECK_EQ(activeFiber_, fiber);
#ifdef FOLLY_SANITIZE_ADDRESS #ifdef FOLLY_SANITIZE_ADDRESS
...@@ -229,7 +229,7 @@ inline bool FiberManager::loopUntilNoReady() { ...@@ -229,7 +229,7 @@ inline bool FiberManager::loopUntilNoReady() {
fiber->rcontext_ = std::move(task->rcontext); fiber->rcontext_ = std::move(task->rcontext);
fiber->setFunction(std::move(task->func)); fiber->setFunction(std::move(task->func));
fiber->data_ = reinterpret_cast<FContext::FiberData>(fiber); fiber->data_ = reinterpret_cast<intptr_t>(fiber);
if (observer_) { if (observer_) {
observer_->runnable(reinterpret_cast<uintptr_t>(fiber)); observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
} }
...@@ -299,7 +299,7 @@ void FiberManager::addTask(F&& func) { ...@@ -299,7 +299,7 @@ void FiberManager::addTask(F&& func) {
fiber->setFunction(std::ref(*funcLoc)); fiber->setFunction(std::ref(*funcLoc));
} }
fiber->data_ = reinterpret_cast<FContext::FiberData>(fiber); fiber->data_ = reinterpret_cast<intptr_t>(fiber);
readyFibers_.push_back(*fiber); readyFibers_.push_back(*fiber);
if (observer_) { if (observer_) {
observer_->runnable(reinterpret_cast<uintptr_t>(fiber)); observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
...@@ -434,7 +434,7 @@ void FiberManager::addTaskFinally(F&& func, G&& finally) { ...@@ -434,7 +434,7 @@ void FiberManager::addTaskFinally(F&& func, G&& finally) {
fiber->setFunctionFinally(std::ref(*funcLoc), std::ref(*finallyLoc)); fiber->setFunctionFinally(std::ref(*funcLoc), std::ref(*finallyLoc));
} }
fiber->data_ = reinterpret_cast<FContext::FiberData>(fiber); fiber->data_ = reinterpret_cast<intptr_t>(fiber);
readyFibers_.push_back(*fiber); readyFibers_.push_back(*fiber);
if (observer_) { if (observer_) {
observer_->runnable(reinterpret_cast<uintptr_t>(fiber)); observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
......
...@@ -341,8 +341,8 @@ class FiberManager : public ::folly::Executor { ...@@ -341,8 +341,8 @@ class FiberManager : public ::folly::Executor {
AtomicIntrusiveLinkedListHook<RemoteTask> nextRemoteTask; AtomicIntrusiveLinkedListHook<RemoteTask> nextRemoteTask;
}; };
FContext::FiberData activateFiber(Fiber* fiber); intptr_t activateFiber(Fiber* fiber);
FContext::FiberData deactivateFiber(Fiber* fiber); intptr_t deactivateFiber(Fiber* fiber);
typedef folly::IntrusiveList<Fiber, &Fiber::listHook_> FiberTailQueue; typedef folly::IntrusiveList<Fiber, &Fiber::listHook_> FiberTailQueue;
typedef folly::IntrusiveList<Fiber, &Fiber::globalListHook_> typedef folly::IntrusiveList<Fiber, &Fiber::globalListHook_>
......
...@@ -69,17 +69,10 @@ AC_DEFUN([AX_BOOST_CONTEXT], ...@@ -69,17 +69,10 @@ AC_DEFUN([AX_BOOST_CONTEXT],
CXXFLAGS_SAVE=$CXXFLAGS CXXFLAGS_SAVE=$CXXFLAGS
AC_COMPILE_IFELSE([AC_LANG_PROGRAM( AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[@%:@include <boost/version.hpp> [[@%:@include <boost/context/fcontext.hpp>
#if BOOST_VERSION >= 106100 #include <boost/version.hpp>
# include <boost/context/detail/fcontext.hpp>
#else
# include <boost/context/fcontext.hpp>
#endif
]], ]],
[[#if BOOST_VERSION >= 106100 [[#if BOOST_VERSION >= 105600
boost::context::detail::fcontext_t fc =
boost::context::detail::make_fcontext(0, 0, 0);
#elif BOOST_VERSION >= 105600
boost::context::fcontext_t fc = boost::context::make_fcontext(0, 0, 0); boost::context::fcontext_t fc = boost::context::make_fcontext(0, 0, 0);
#else #else
boost::context::fcontext_t* fc = boost::context::make_fcontext(0, 0, 0); boost::context::fcontext_t* fc = boost::context::make_fcontext(0, 0, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment