编译plugin_boost出错
Opened this issue · 2 comments
ezxfv commented
OS: Ubuntu18.04 64bit
GCC: 8.0
Boost: 1.66
由于使用到的boost::context下的类和函数已经转移到boost::context::detail下,并且有的函数参数发生变化,需要进行更改plugin_boost/network下的uthread_context_boost.h和uthread_context_boost.cpp,之后可以成功编译,但是未进行测试.
代码中中文注释部分为修改的地方.
其中uthread_context_boost.h改为:
#pragma once
#include <unistd.h>
#include <functional>
#include <assert.h>
#include <boost/context/all.hpp>
#include "phxrpc/network.h"
// 添加
using boost::context::detail::fcontext_t;
using boost::context::detail::transfer_t;
namespace phxrpc {
class UThreadContextBoostInit {
public:
UThreadContextBoostInit();
};
class UThreadContextBoost : public UThreadContext {
public:
UThreadContextBoost(size_t stack_size, UThreadFunc_t func, void * args,
UThreadDoneCallback_t callback, const bool need_stack_protect);
~UThreadContextBoost();
static UThreadContext * DoCreate(size_t stack_size,
UThreadFunc_t func, void * args, UThreadDoneCallback_t callback,
const bool need_stack_protect);
void Make(UThreadFunc_t func, void * args) override;
bool Resume() override;
bool Yield() override;
fcontext_t & GetMainContext();
private:
// 参数从intptr_t变为transfer_t
static void UThreadFuncWrapper(transfer_t ptr);
fcontext_t context_;
UThreadFunc_t func_;
void * args_;
UThreadStackMemory stack_;
UThreadDoneCallback_t callback_;
};
} //namespace phxrpc
uthread_context_boost.cpp改为:
#include <unistd.h>
#include <functional>
#include <assert.h>
#include <boost/context/all.hpp>
#include "uthread_context_boost.h"
#include "phxrpc/network.h"
using boost::context::detail::transfer_t;
using boost::context::detail::fcontext_t;
using boost::context::detail::jump_fcontext;
using boost::context::detail::make_fcontext;
namespace phxrpc {
UThreadContextBoostInit g_uthread_context_boost_init_;
UThreadContextBoostInit :: UThreadContextBoostInit() {
UThreadContext::SetContextCreateFunc(UThreadContextBoost::DoCreate);
}
UThreadContextBoost :: UThreadContextBoost(size_t stack_size, UThreadFunc_t func,
void * args, UThreadDoneCallback_t callback, const bool need_stack_protect)
: func_(func), args_(args), stack_(stack_size, need_stack_protect), callback_(callback) {
Make(func, args);
}
UThreadContextBoost :: ~UThreadContextBoost() {
}
UThreadContext * UThreadContextBoost:: DoCreate(size_t stack_size,
UThreadFunc_t func, void * args, UThreadDoneCallback_t callback,
const bool need_stack_protect) {
return new UThreadContextBoost(stack_size, func, args, callback, need_stack_protect);
}
// 参数从intptr_t变为transfer_t
void UThreadContextBoost :: UThreadFuncWrapper(transfer_t ptr) {
// 类型转换前将transfer_t取地址转为intptr_t
UThreadContextBoost * uc = reinterpret_cast<UThreadContextBoost *>(intptr_t(&ptr));
uc->func_(uc->args_);
if (uc->callback_ != nullptr) {
uc->callback_();
}
uc->Yield();
}
void UThreadContextBoost :: Make(UThreadFunc_t func, void * args) {
func_ = func;
args_ = args;
void * stack_p = (void *)((char *)stack_.top() + stack_.size());
context_ = make_fcontext(stack_p, stack_.size(), &UThreadFuncWrapper);
}
bool UThreadContextBoost :: Resume() {
//boost::context::detail::jump_fcontext(&GetMainContext(), context_, reinterpret_cast<intptr_t>(this));
//删除最后一个参数
jump_fcontext(&GetMainContext(), context_);
return true;
}
bool UThreadContextBoost :: Yield() {
//boost::context::detail::jump_fcontext(&context_, GetMainContext(), 0);
// 删除最后一个参数
jump_fcontext(&context_, GetMainContext());
return true;
}
fcontext_t & UThreadContextBoost :: GetMainContext() {
static thread_local fcontext_t main_context;
return main_context;
}
} //namespace phxrpc
taohexxx commented
谢谢,建议提交PullRequest
zhenxiaoyuan commented
OS: Fedora28 64bit
GCC: 8.1.1
Boost: 1.68
编译报错:
fatal error: boost/context/all.hpp: No such file or directory
解决方法:
// #include <boost/context/all.hpp>
// 修改为
#include <boost/context/detail/fcontext.hpp>