Sync develop with master #4

Merged
RoshanSyed merged 144 commits from master into develop 2019-12-16 15:20:56 +00:00
2 changed files with 10 additions and 68 deletions
Showing only changes of commit d1faea2bde - Show all commits

View file

@ -4,8 +4,6 @@
#include <fc/exception/exception.hpp> #include <fc/exception/exception.hpp>
#include <vector> #include <vector>
#include <iostream>
#include <boost/version.hpp> #include <boost/version.hpp>
#if BOOST_VERSION >= 105400 #if BOOST_VERSION >= 105400
@ -45,17 +43,12 @@ namespace fc {
struct context { struct context {
typedef fc::context* ptr; typedef fc::context* ptr;
#if BOOST_VERSION >= 105400 // && BOOST_VERSION <= 106100 #if BOOST_VERSION >= 105400
bco::stack_context stack_ctx; bco::stack_context stack_ctx;
#endif #endif
#if BOOST_VERSION >= 106100
typedef bc::detail::transfer_t transfer_t;
#else
typedef intptr_t transfer_t;
#endif
context( void (*sf)(transfer_t), stack_allocator& alloc, fc::thread* t ) context( void (*sf)(intptr_t), stack_allocator& alloc, fc::thread* t )
: caller_context(0), : caller_context(0),
stack_alloc(&alloc), stack_alloc(&alloc),
next_blocked(0), next_blocked(0),
@ -70,13 +63,7 @@ namespace fc {
cur_task(0), cur_task(0),
context_posted_num(0) context_posted_num(0)
{ {
#if BOOST_VERSION >= 106100 #if BOOST_VERSION >= 105600
// std::cerr<< "HERE: "<< BOOST_VERSION <<"\n";
//my_context = new bc::execution_context<intptr_t>( [=]( bc::execution_context<intptr_t> sink, intptr_t self ){ std::cerr<<"in ex\n"; sf(self); std::cerr<<"exit ex\n"; return sink; } );
size_t stack_size = FC_CONTEXT_STACK_SIZE;
alloc.allocate(stack_ctx, stack_size);
my_context = bc::detail::make_fcontext( stack_ctx.sp, stack_ctx.size, sf );
#elif BOOST_VERSION >= 105600
size_t stack_size = FC_CONTEXT_STACK_SIZE; size_t stack_size = FC_CONTEXT_STACK_SIZE;
alloc.allocate(stack_ctx, stack_size); alloc.allocate(stack_ctx, stack_size);
my_context = bc::make_fcontext( stack_ctx.sp, stack_ctx.size, sf); my_context = bc::make_fcontext( stack_ctx.sp, stack_ctx.size, sf);
@ -97,7 +84,7 @@ namespace fc {
} }
context( fc::thread* t) : context( fc::thread* t) :
#if BOOST_VERSION >= 105600 && BOOST_VERSION <= 106100 #if BOOST_VERSION >= 105600
my_context(nullptr), my_context(nullptr),
#elif BOOST_VERSION >= 105300 #elif BOOST_VERSION >= 105300
my_context(new bc::fcontext_t), my_context(new bc::fcontext_t),
@ -115,21 +102,10 @@ namespace fc {
complete(false), complete(false),
cur_task(0), cur_task(0),
context_posted_num(0) context_posted_num(0)
{ {}
#if BOOST_VERSION >= 106100
/*
bc::execution_context<intptr_t> tmp( [=]( bc::execution_context<intptr_t> sink, intptr_t ) { std::cerr<<"get current\n"; return sink; } );
auto result = tmp(0);
my_context = new bc::execution_context<intptr_t>( std::move( std::get<0>(result) ) );
*/
#endif
}
~context() { ~context() {
#if BOOST_VERSION >= 106100 #if BOOST_VERSION >= 105600
// delete my_context;
#elif BOOST_VERSION >= 105600
if(stack_alloc) if(stack_alloc)
stack_alloc->deallocate( stack_ctx ); stack_alloc->deallocate( stack_ctx );
#elif BOOST_VERSION >= 105400 #elif BOOST_VERSION >= 105400
@ -233,11 +209,7 @@ namespace fc {
#if BOOST_VERSION >= 105300 && BOOST_VERSION < 105600
#if BOOST_VERSION >= 106100
//bc::execution_context<intptr_t>* my_context;
bc::detail::fcontext_t my_context;
#elif BOOST_VERSION >= 105300 && BOOST_VERSION < 105600
bc::fcontext_t* my_context; bc::fcontext_t* my_context;
#else #else
bc::fcontext_t my_context; bc::fcontext_t my_context;

View file

@ -18,8 +18,6 @@ namespace fc {
class thread_d { class thread_d {
public: public:
fc::context* prev_ctx = nullptr;
thread_d(fc::thread& s) thread_d(fc::thread& s)
:self(s), boost_thread(0), :self(s), boost_thread(0),
task_in_queue(0), task_in_queue(0),
@ -399,12 +397,7 @@ namespace fc {
} }
// slog( "jump to %p from %p", next, prev ); // slog( "jump to %p from %p", next, prev );
// fc_dlog( logger::get("fc_context"), "from ${from} to ${to}", ( "from", int64_t(prev) )( "to", int64_t(next) ) ); // fc_dlog( logger::get("fc_context"), "from ${from} to ${to}", ( "from", int64_t(prev) )( "to", int64_t(next) ) );
#if BOOST_VERSION >= 106100 #if BOOST_VERSION >= 105600
prev_ctx = prev;
std::cerr<<"start jumping to existing context...\n";
bc::detail::jump_fcontext( next->my_context, this );
std::cerr<<"back from jumping to existing context\n";
#elif BOOST_VERSION >= 105600
bc::jump_fcontext( &prev->my_context, next->my_context, 0 ); bc::jump_fcontext( &prev->my_context, next->my_context, 0 );
#elif BOOST_VERSION >= 105300 #elif BOOST_VERSION >= 105300
bc::jump_fcontext( prev->my_context, next->my_context, 0 ); bc::jump_fcontext( prev->my_context, next->my_context, 0 );
@ -446,16 +439,7 @@ namespace fc {
// slog( "jump to %p from %p", next, prev ); // slog( "jump to %p from %p", next, prev );
// fc_dlog( logger::get("fc_context"), "from ${from} to ${to}", ( "from", int64_t(prev) )( "to", int64_t(next) ) ); // fc_dlog( logger::get("fc_context"), "from ${from} to ${to}", ( "from", int64_t(prev) )( "to", int64_t(next) ) );
#if BOOST_VERSION >= 106100 #if BOOST_VERSION >= 105600
//(*next->my_context)( (intptr_t)this );
//bc::detail::transfer_t tran; tran.data = this;
std::cerr << "start prev->my_context = " << prev->my_context <<"... \n";
std::cerr << "jumping to next context... \n";
prev_ctx = prev;
auto result = bc::detail::jump_fcontext( next->my_context, this );
std::cerr << "end prev->my_context = " << prev->my_context <<"... \n";
std::cerr << result.fctx <<" <--- result \n";
#elif BOOST_VERSION >= 105600
bc::jump_fcontext( &prev->my_context, next->my_context, (intptr_t)this ); bc::jump_fcontext( &prev->my_context, next->my_context, (intptr_t)this );
#elif BOOST_VERSION >= 105300 #elif BOOST_VERSION >= 105300
bc::jump_fcontext( prev->my_context, next->my_context, (intptr_t)this ); bc::jump_fcontext( prev->my_context, next->my_context, (intptr_t)this );
@ -483,22 +467,9 @@ namespace fc {
return true; return true;
} }
static void start_process_tasks( fc::context::transfer_t my ) static void start_process_tasks( intptr_t my )
{ {
#if BOOST_VERSION >= 106100
std::cerr<<"my data: "<<my.data<<"\n";
std::cerr<<"my from: "<<my.fctx<<"\n";
thread_d* self = (thread_d*)my.data;
if( self->prev_ctx )
{
std::cerr << "setting prev_ctx to " << int64_t(my.fctx) << "\n";
self->prev_ctx->my_context = my.fctx;
}
std::cerr<<"start process tasks\n" << int64_t(self)<<"\n";
assert( self != 0 );
#else
thread_d* self = (thread_d*)my; thread_d* self = (thread_d*)my;
#endif
try try
{ {
self->process_tasks(); self->process_tasks();
@ -513,7 +484,6 @@ namespace fc {
} }
self->free_list.push_back(self->current); self->free_list.push_back(self->current);
self->start_next_fiber( false ); self->start_next_fiber( false );
std::cerr << "existing start process tasks \n ";
} }
void run_next_task() void run_next_task()