2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-18 01:52:24 +00:00

unwind at shutdown

- scheduler holds a list of managed worker-fibers
- ~scheduler() requests stack unwinding for fibers not yet terminated
This commit is contained in:
Oliver Kowalke
2015-09-24 17:35:40 +02:00
parent 1f88055f42
commit fc404c58eb
5 changed files with 172 additions and 31 deletions

View File

@@ -58,9 +58,11 @@ context::context( main_context_t) :
flags_( flag_main_context),
scheduler_( nullptr),
ctx_( boost::context::execution_context::current() ),
worker_hook_(),
terminated_hook_(),
ready_hook_(),
remote_ready_hook_(),
terminated_hook_(),
sleep_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
fss_data_(),
@@ -81,9 +83,11 @@ 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");
}),
worker_hook_(),
terminated_hook_(),
ready_hook_(),
remote_ready_hook_(),
terminated_hook_(),
sleep_hook_(),
wait_hook_(),
tp_( (std::chrono::steady_clock::time_point::max)() ),
fss_data_(),
@@ -196,6 +200,8 @@ void
context::set_ready( context * ctx) noexcept {
BOOST_ASSERT( nullptr != ctx);
BOOST_ASSERT( this != ctx);
BOOST_ASSERT( nullptr != scheduler_);
BOOST_ASSERT( nullptr != ctx->scheduler_);
// FIXME: comparing scheduler address' must be synchronized?
// what if ctx is migrated between threads
// (other scheduler assigned)
@@ -227,6 +233,13 @@ context::request_interruption( bool req) noexcept {
}
}
void
context::request_unwinding() noexcept {
BOOST_ASSERT( ! is_main_context() );
BOOST_ASSERT( ! is_dispatcher_context() );
flags_ |= flag_forced_unwind;
}
void *
context::get_fss_data( void const * vp) const {
uintptr_t key( reinterpret_cast< uintptr_t >( vp) );
@@ -263,6 +276,11 @@ context::set_fss_data( void const * vp,
}
}
bool
context::managed_is_linked() {
return worker_hook_.is_linked();
}
bool
context::ready_is_linked() {
return ready_hook_.is_linked();
@@ -283,6 +301,11 @@ context::wait_is_linked() {
return wait_hook_.is_linked();
}
void
context::managed_unlink() {
worker_hook_.unlink();
}
void
context::sleep_unlink() {
sleep_hook_.unlink();