return false;
}
context * active_ctx = context::active();
- // store this fiber in order to be notified later
detail::spinlock_lock lk{ wait_queue_splk_ };
if ( nullptr == owner_) {
owner_ = active_ctx;
return true;
}
- BOOST_ASSERT( ! active_ctx->wait_is_linked() );
- active_ctx->wait_link( wait_queue_);
- active_ctx->twstatus.store( reinterpret_cast< std::intptr_t >( this), std::memory_order_release);
- // suspend this fiber until notified or timed-out
- if ( ! active_ctx->wait_until( timeout_time, lk) ) {
- // remove fiber from wait-queue
- lk.lock();
- wait_queue_.remove( * active_ctx);
+ if ( ! wait_queue_.suspend_and_wait_until( lk, active_ctx, timeout_time)) {
return false;
}
- BOOST_ASSERT( ! active_ctx->wait_is_linked() );
}
}
owner_ = active_ctx;
return;
}
- BOOST_ASSERT( ! active_ctx->wait_is_linked() );
- active_ctx->wait_link( wait_queue_);
- active_ctx->twstatus.store( static_cast< std::intptr_t >( 0), std::memory_order_release);
- // suspend this fiber
- active_ctx->suspend( lk);
- BOOST_ASSERT( ! active_ctx->wait_is_linked() );
+ wait_queue_.suspend_and_wait( lk, active_ctx);
}
}
"boost fiber: no privilege to perform the operation" };
}
owner_ = nullptr;
- if ( ! wait_queue_.empty() ) {
- context * ctx = & wait_queue_.front();
- wait_queue_.pop_front();
- auto expected = reinterpret_cast< std::intptr_t >( this);
- if ( ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
- // notify context
- active_ctx->schedule( ctx);
- } else if ( static_cast< std::intptr_t >( 0) == expected) {
- // no timed-wait op.
- // notify context
- active_ctx->schedule( ctx);
- }
- }
+
+ wait_queue_.notify_one();
}
}}