diff --git a/src/fiber.cpp b/src/fiber.cpp index 7125b6b0..a9fa597b 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -32,17 +32,13 @@ fiber::join() { throw fiber_resource_error( static_cast< int >( std::errc::resource_deadlock_would_occur), "boost fiber: trying to join itself"); } - if ( ! joinable() ) { throw fiber_resource_error( static_cast< int >( std::errc::invalid_argument), "boost fiber: fiber not joinable"); } - ptr_t tmp; tmp.swap( impl_); - tmp->join(); - // TODO: call interruption_point() } diff --git a/src/mutex.cpp b/src/mutex.cpp index 69a23a91..2e6b9045 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -24,11 +24,9 @@ mutex::lock_if_unlocked_() { if ( mutex_status::locked == state_.load( std::memory_order_relaxed) ) { return false; } - if ( mutex_status::unlocked != state_.exchange( mutex_status::locked, std::memory_order_acquire) ) { return false; } - BOOST_ASSERT( nullptr == owner_); owner_ = context::active(); return true; @@ -54,16 +52,13 @@ mutex::lock() { if ( lock_if_unlocked_() ) { return; } - // store this fiber in order to be notified later detail::spinlock_lock lk( wait_queue_splk_); BOOST_ASSERT( ! ctx->wait_is_linked() ); wait_queue_.push_back( * ctx); lk.unlock(); - // suspend this fiber ctx->suspend(); - // remove fiber from wait-queue lk.lock(); ctx->wait_unlink(); @@ -81,7 +76,6 @@ mutex::try_lock() { if ( lock_if_unlocked_() ) { return true; } - // let other fiber release the lock context::active()->yield(); return false; @@ -91,7 +85,6 @@ void mutex::unlock() { BOOST_ASSERT( mutex_status::locked == state_); BOOST_ASSERT( context::active() == owner_); - detail::spinlock_lock lk( wait_queue_splk_); context * ctx( nullptr); if ( ! wait_queue_.empty() ) { @@ -102,7 +95,6 @@ mutex::unlock() { lk.unlock(); owner_ = nullptr; state_.store( mutex_status::unlocked, std::memory_order_release); - if ( nullptr != ctx) { context::active()->set_ready( ctx); } diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp index a2faa09e..86c078f7 100644 --- a/src/recursive_mutex.cpp +++ b/src/recursive_mutex.cpp @@ -29,7 +29,6 @@ recursive_mutex::lock_if_unlocked_() { return false; } } - if ( mutex_status::unlocked != state_.exchange( mutex_status::locked, std::memory_order_acquire) ) { if ( context::active() == owner_) { ++count_; @@ -38,7 +37,6 @@ recursive_mutex::lock_if_unlocked_() { return false; } } - BOOST_ASSERT( nullptr == owner_); owner_ = context::active(); ++count_; @@ -67,16 +65,13 @@ recursive_mutex::lock() { if ( lock_if_unlocked_() ) { return; } - // store this fiber in order to be notified later detail::spinlock_lock lk( wait_queue_splk_); BOOST_ASSERT( ! ctx->wait_is_linked() ); wait_queue_.push_back( * ctx); lk.unlock(); - // suspend this fiber ctx->suspend(); - // remove fiber from wait-queue lk.lock(); ctx->wait_unlink(); @@ -94,7 +89,6 @@ recursive_mutex::try_lock() { if ( lock_if_unlocked_() ) { return true; } - // let other fiber release the lock context::active()->yield(); return false; @@ -104,7 +98,6 @@ void recursive_mutex::unlock() { BOOST_ASSERT( mutex_status::locked == state_); BOOST_ASSERT( context::active() == owner_); - detail::spinlock_lock lk( wait_queue_splk_); context * ctx( nullptr); if ( 0 == --count_) { @@ -116,7 +109,6 @@ recursive_mutex::unlock() { lk.unlock(); owner_ = nullptr; state_.store( mutex_status::unlocked, std::memory_order_release); - if ( nullptr != ctx) { context::active()->set_ready( ctx); } diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp index 83071712..ee92496a 100644 --- a/src/recursive_timed_mutex.cpp +++ b/src/recursive_timed_mutex.cpp @@ -30,7 +30,6 @@ recursive_timed_mutex::lock_if_unlocked_() { return false; } } - if ( mutex_status::unlocked != state_.exchange( mutex_status::locked, std::memory_order_acquire) ) { if ( context::active() == owner_) { ++count_; @@ -39,7 +38,6 @@ recursive_timed_mutex::lock_if_unlocked_() { return false; } } - BOOST_ASSERT( nullptr == owner_); owner_ = context::active(); ++count_; @@ -68,16 +66,13 @@ recursive_timed_mutex::lock() { if ( lock_if_unlocked_() ) { return; } - // store this fiber in order to be notified later detail::spinlock_lock lk( wait_queue_splk_); BOOST_ASSERT( ! ctx->wait_is_linked() ); wait_queue_.push_back( * ctx); lk.unlock(); - // suspend this fiber ctx->suspend(); - // remove fiber from wait-queue lk.lock(); ctx->wait_unlink(); @@ -95,7 +90,6 @@ recursive_timed_mutex::try_lock() { if ( lock_if_unlocked_() ) { return true; } - // let other fiber release the lock context::active()->yield(); return false; @@ -109,17 +103,14 @@ recursive_timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point co if ( std::chrono::steady_clock::now() > timeout_time) { return false; } - if ( lock_if_unlocked_() ) { return true; } - // store this fiber in order to be notified later detail::spinlock_lock lk( wait_queue_splk_); BOOST_ASSERT( ! ctx->wait_is_linked() ); wait_queue_.push_back( * ctx); lk.unlock(); - // suspend this fiber until notified or timed-out if ( ! ctx->wait_until( timeout_time) ) { // remove fiber from wait-queue @@ -127,7 +118,6 @@ recursive_timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point co ctx->wait_unlink(); return false; } - // remove fiber from wait-queue lk.lock(); ctx->wait_unlink(); @@ -144,7 +134,6 @@ void recursive_timed_mutex::unlock() { BOOST_ASSERT( mutex_status::locked == state_); BOOST_ASSERT( context::active() == owner_); - detail::spinlock_lock lk( wait_queue_splk_); context * ctx( nullptr); if ( 0 == --count_) { @@ -156,7 +145,6 @@ recursive_timed_mutex::unlock() { lk.unlock(); owner_ = nullptr; state_.store( mutex_status::unlocked, std::memory_order_release); - if ( nullptr != ctx) { context::active()->set_ready( ctx); } diff --git a/src/scheduler.cpp b/src/scheduler.cpp index de921f2d..6a53a12d 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -101,7 +101,6 @@ scheduler::~scheduler() noexcept { BOOST_ASSERT( nullptr != main_ctx_); BOOST_ASSERT( nullptr != dispatcher_ctx_.get() ); BOOST_ASSERT( context::active() == main_ctx_); - // signal dispatcher context termination shutdown_ = true; // resume pending fibers diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp index b187c3b6..743b69f6 100644 --- a/src/timed_mutex.cpp +++ b/src/timed_mutex.cpp @@ -25,11 +25,9 @@ timed_mutex::lock_if_unlocked_() { if ( mutex_status::locked == state_.load( std::memory_order_relaxed) ) { return false; } - if ( mutex_status::unlocked != state_.exchange( mutex_status::locked, std::memory_order_acquire) ) { return false; } - BOOST_ASSERT( nullptr == owner_); owner_ = context::active(); return true; @@ -55,16 +53,13 @@ timed_mutex::lock() { if ( lock_if_unlocked_() ) { return; } - // store this fiber in order to be notified later detail::spinlock_lock lk( wait_queue_splk_); BOOST_ASSERT( ! ctx->wait_is_linked() ); wait_queue_.push_back( * ctx); lk.unlock(); - // suspend this fiber ctx->suspend(); - // remove fiber from wait-queue lk.lock(); ctx->wait_unlink(); @@ -82,7 +77,6 @@ timed_mutex::try_lock() { if ( lock_if_unlocked_() ) { return true; } - // let other fiber release the lock context::active()->yield(); return false; @@ -96,17 +90,14 @@ timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeo if ( std::chrono::steady_clock::now() > timeout_time) { return false; } - if ( lock_if_unlocked_() ) { return true; } - // store this fiber in order to be notified later detail::spinlock_lock lk( wait_queue_splk_); BOOST_ASSERT( ! ctx->wait_is_linked() ); wait_queue_.push_back( * ctx); lk.unlock(); - // suspend this fiber until notified or timed-out if ( ! context::active()->wait_until( timeout_time) ) { // remove fiber from wait-queue @@ -114,7 +105,6 @@ timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeo ctx->wait_unlink(); return false; } - // remove fiber from wait-queue lk.lock(); ctx->wait_unlink(); @@ -131,7 +121,6 @@ void timed_mutex::unlock() { BOOST_ASSERT( mutex_status::locked == state_); BOOST_ASSERT( context::active() == owner_); - detail::spinlock_lock lk( wait_queue_splk_); context * ctx( nullptr); if ( ! wait_queue_.empty() ) { @@ -142,7 +131,6 @@ timed_mutex::unlock() { lk.unlock(); owner_ = nullptr; state_.store( mutex_status::unlocked, std::memory_order_relaxed); - if ( nullptr != ctx) { context::active()->set_ready( ctx); }