2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-16 13:22:17 +00:00

reorder member variables of context

- member hooks must be destroyed before execution_context
- otherwise an segementation fault is caused
- destruction of execution_context deallocates stack on which
  the member variables of context are allocated
This commit is contained in:
Oliver Kowalke
2015-09-20 11:25:32 +02:00
parent 067547f18e
commit b3660a3432
2 changed files with 30 additions and 27 deletions

View File

@@ -98,18 +98,6 @@ struct worker_context_t {};
constexpr worker_context_t worker_context = worker_context_t();
class BOOST_FIBERS_DECL context {
public:
detail::ready_hook ready_hook_;
detail::sleep_hook sleep_hook_;
detail::terminated_hook terminated_hook_;
detail::wait_hook wait_hook_;
std::chrono::steady_clock::time_point tp_;
typedef intrusive::list<
context,
intrusive::function_hook< detail::wait_functor >,
intrusive::constant_time_size< false > > wait_queue_t;
private:
enum flag_t {
flag_main_context = 1 << 1,
@@ -129,6 +117,20 @@ private:
#endif
scheduler * scheduler_;
boost::context::execution_context ctx_;
public:
detail::ready_hook ready_hook_;
detail::sleep_hook sleep_hook_;
detail::terminated_hook terminated_hook_;
detail::wait_hook wait_hook_;
std::chrono::steady_clock::time_point tp_;
typedef intrusive::list<
context,
intrusive::function_hook< detail::wait_functor >,
intrusive::constant_time_size< false > > wait_queue_t;
private:
wait_queue_t wait_queue_;
detail::spinlock splk_;
@@ -207,10 +209,6 @@ public:
context( worker_context_t,
boost::context::preallocated palloc, StackAlloc salloc,
Fn && fn, Args && ... args) :
ready_hook_(),
terminated_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
use_count_( 1), // fiber instance or scheduler owner
flags_( flag_worker_context),
scheduler_( nullptr),
@@ -228,7 +226,12 @@ public:
suspend();
BOOST_ASSERT_MSG( false, "fiber already terminated");
}),
wait_queue_() {
ready_hook_(),
terminated_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
wait_queue_(),
splk_() {
}
virtual ~context();

View File

@@ -52,14 +52,14 @@ context::set_terminated_() noexcept {
// main fiber context
context::context( main_context_t) :
ready_hook_(),
terminated_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
use_count_( 1), // allocated on main- or thread-stack
flags_( flag_main_context),
scheduler_( nullptr),
ctx_( boost::context::execution_context::current() ),
ready_hook_(),
terminated_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
wait_queue_(),
splk_() {
}
@@ -67,10 +67,6 @@ context::context( main_context_t) :
// dispatcher fiber context
context::context( dispatcher_context_t, boost::context::preallocated const& palloc,
fixedsize_stack const& salloc, scheduler * sched) :
ready_hook_(),
terminated_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
use_count_( 0), // scheduler will own dispatcher context
flags_( flag_dispatcher_context),
scheduler_( nullptr),
@@ -81,6 +77,10 @@ context::context( dispatcher_context_t, boost::context::preallocated const& pall
// dispatcher context should never return from scheduler::dispatch()
BOOST_ASSERT_MSG( false, "disatcher fiber already terminated");
}),
ready_hook_(),
terminated_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
wait_queue_(),
splk_() {
}
@@ -129,11 +129,11 @@ context::release() noexcept {
// notify all waiting fibers
wait_queue_t::iterator e = tmp.end();
for ( wait_queue_t::iterator i = tmp.begin(); i != e;) {
context * f = & ( * i);
context * ctx = & ( * i);
// remove fiber from wait-queue
i = tmp.erase( i);
// notify scheduler
scheduler_->set_ready( f);
scheduler_->set_ready( ctx);
}
}