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

Merge pull request #77 from nat-goodspeed/develop

Defend yield_handler_base::operator() against immediate callback.
This commit is contained in:
Oliver Kowalke
2016-04-02 19:17:32 +02:00

View File

@@ -85,16 +85,22 @@ public:
ycomp_->completed_ = true;
// set the error_code bound by yield_t
* yt_.ec_ = ec;
// Are we permitted to wake up the suspended fiber on this thread, the
// thread that called the completion handler?
if ( ( ! ctx_->is_context( fibers::type::pinned_context) ) && yt_.allow_hop_) {
// We must not migrate a pinned_context to another thread. If this
// isn't a pinned_context, and the application passed yield_hop
// rather than yield, migrate this fiber to the running thread.
fibers::context::active()->migrate( ctx_);
// If ctx_ is still active, e.g. because the async operation
// immediately called its callback (this method!) before the asio
// async function called async_result_base::get(), we must neither
// migrate it nor set it ready.
if ( fibers::context::active() != ctx_ ) {
// Are we permitted to wake up the suspended fiber on this thread, the
// thread that called the completion handler?
if ( ( ! ctx_->is_context( fibers::type::pinned_context) ) && yt_.allow_hop_) {
// We must not migrate a pinned_context to another thread. If this
// isn't a pinned_context, and the application passed yield_hop
// rather than yield, migrate this fiber to the running thread.
fibers::context::active()->migrate( ctx_);
}
// either way, wake the fiber
fibers::context::active()->set_ready( ctx_);
}
// either way, wake the fiber
fibers::context::active()->set_ready( ctx_);
}
//private: