]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/fiber/src/timed_mutex.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / fiber / src / timed_mutex.cpp
index f33ed956083797b48db0f1ffdd45aa317654b61e..d0482c5ca2d51978a1a163138ed3461b23f9a42d 100644 (file)
@@ -26,23 +26,14 @@ timed_mutex::try_lock_until_( std::chrono::steady_clock::time_point const& timeo
             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() );
     }
 }
 
@@ -61,12 +52,7 @@ timed_mutex::lock() {
             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);
     }
 }
 
@@ -98,19 +84,8 @@ timed_mutex::unlock() {
                 "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();
 }
 
 }}