]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/fiber/buffered_channel.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / fiber / buffered_channel.hpp
index 592a6340d54a8a20ff1018fee732df86e9679e42..4086efa72f9a1ffe21ed89eff611f727014611f0 100644 (file)
@@ -87,33 +87,35 @@ public:
     void close() noexcept {
         context * active_ctx = context::active();
         detail::spinlock_lock lk{ splk_ };
-        closed_ = true;
-        // notify all waiting producers
-        while ( ! waiting_producers_.empty() ) {
-            context * producer_ctx = & waiting_producers_.front();
-            waiting_producers_.pop_front();
-            std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
-            if ( producer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
-                // notify context
-                active_ctx->schedule( producer_ctx);
-            } else if ( static_cast< std::intptr_t >( 0) == expected) {
-                // no timed-wait op.
-                // notify context
-                active_ctx->schedule( producer_ctx);
+        if ( ! closed_) {
+            closed_ = true;
+            // notify all waiting producers
+            while ( ! waiting_producers_.empty() ) {
+                context * producer_ctx = & waiting_producers_.front();
+                waiting_producers_.pop_front();
+                std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
+                if ( producer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                    // notify context
+                    active_ctx->schedule( producer_ctx);
+                } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                    // no timed-wait op.
+                    // notify context
+                    active_ctx->schedule( producer_ctx);
+                }
             }
-        }
-        // notify all waiting consumers
-        while ( ! waiting_consumers_.empty() ) {
-            context * consumer_ctx = & waiting_consumers_.front();
-            waiting_consumers_.pop_front();
-            std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
-            if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
-                // notify context
-                active_ctx->schedule( consumer_ctx);
-            } else if ( static_cast< std::intptr_t >( 0) == expected) {
-                // no timed-wait op.
-                // notify context
-                active_ctx->schedule( consumer_ctx);
+            // notify all waiting consumers
+            while ( ! waiting_consumers_.empty() ) {
+                context * consumer_ctx = & waiting_consumers_.front();
+                waiting_consumers_.pop_front();
+                std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
+                if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                    // notify context
+                    active_ctx->schedule( consumer_ctx);
+                } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                    // no timed-wait op.
+                    // notify context
+                    active_ctx->schedule( consumer_ctx);
+                }
             }
         }
     }
@@ -134,10 +136,12 @@ public:
                 waiting_consumers_.pop_front();
                 std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                 if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                    lk.unlock();
                     // notify context
                     active_ctx->schedule( consumer_ctx);
                     break;
                 } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                    lk.unlock();
                     // no timed-wait op.
                     // notify context
                     active_ctx->schedule( consumer_ctx);
@@ -162,13 +166,14 @@ public:
             while ( ! waiting_consumers_.empty() ) {
                 context * consumer_ctx = & waiting_consumers_.front();
                 waiting_consumers_.pop_front();
-                lk.unlock();
                 std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                 if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                    lk.unlock();
                     // notify context
                     active_ctx->schedule( consumer_ctx);
                     break;
                 } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                    lk.unlock();
                     // no timed-wait op.
                     // notify context
                     active_ctx->schedule( consumer_ctx);
@@ -197,13 +202,14 @@ public:
                 while ( ! waiting_consumers_.empty() ) {
                     context * consumer_ctx = & waiting_consumers_.front();
                     waiting_consumers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( consumer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( consumer_ctx);
@@ -233,13 +239,14 @@ public:
                 while ( ! waiting_consumers_.empty() ) {
                     context * consumer_ctx = & waiting_consumers_.front();
                     waiting_consumers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( consumer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( consumer_ctx);
@@ -292,13 +299,14 @@ public:
                 while ( ! waiting_consumers_.empty() ) {
                     context * consumer_ctx = & waiting_consumers_.front();
                     waiting_consumers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( consumer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( consumer_ctx);
@@ -337,13 +345,14 @@ public:
                 while ( ! waiting_consumers_.empty() ) {
                     context * consumer_ctx = & waiting_consumers_.front();
                     waiting_consumers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( consumer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( consumer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( consumer_ctx);
@@ -369,13 +378,14 @@ public:
             while ( ! waiting_producers_.empty() ) {
                 context * producer_ctx = & waiting_producers_.front();
                 waiting_producers_.pop_front();
-                lk.unlock();
                 std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                 if ( producer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                    lk.unlock();
                     // notify context
                     active_ctx->schedule( producer_ctx);
                     break;
                 } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                    lk.unlock();
                     // no timed-wait op.
                     // notify context
                     active_ctx->schedule( producer_ctx);
@@ -406,13 +416,14 @@ public:
                 while ( ! waiting_producers_.empty() ) {
                     context * producer_ctx = & waiting_producers_.front();
                     waiting_producers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( producer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( producer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( producer_ctx);
@@ -446,13 +457,14 @@ public:
                 while ( ! waiting_producers_.empty() ) {
                     context * producer_ctx = & waiting_producers_.front();
                     waiting_producers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( producer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( producer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( producer_ctx);
@@ -500,13 +512,14 @@ public:
                 while ( ! waiting_producers_.empty() ) {
                     context * producer_ctx = & waiting_producers_.front();
                     waiting_producers_.pop_front();
-                    lk.unlock();
                     std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
                     if ( producer_ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
+                        lk.unlock();
                         // notify context
                         active_ctx->schedule( producer_ctx);
                         break;
                     } else if ( static_cast< std::intptr_t >( 0) == expected) {
+                        lk.unlock();
                         // no timed-wait op.
                         // notify context
                         active_ctx->schedule( producer_ctx);
@@ -570,6 +583,7 @@ public:
         }
 
         iterator & operator++() {
+            reinterpret_cast< value_type * >( std::addressof( storage_) )->~value_type();
             increment_();
             return * this;
         }