fixed empy function in flat combiner containers
authorMarsel Galimullin <mfgalimullin@yandex.ru>
Thu, 7 May 2015 19:49:12 +0000 (22:49 +0300)
committerMarsel Galimullin <mfgalimullin@yandex.ru>
Thu, 7 May 2015 19:49:12 +0000 (22:49 +0300)
cds/container/fcdeque.h
cds/container/fcpriority_queue.h
cds/container/fcqueue.h
cds/container/fcstack.h

index 55dbb33b8718bc8fd9ebd58cf1cc1b0ad61efc15..c179a6e09e955118c4302dae79f73651607951a3 100644 (file)
@@ -133,7 +133,8 @@ namespace cds { namespace container {
             op_push_back_move,      ///< Push back (move semantics)
             op_pop_front,           ///< Pop front
             op_pop_back,            ///< Pop back
-            op_clear                ///< Clear
+            op_clear,               ///< Clear
+            op_empty                ///< Empty
         };
 
         /// Flat combining publication list record
@@ -332,10 +333,18 @@ namespace cds { namespace container {
         /**
             If the combining is in process the function waits while combining done.
         */
-        bool empty() const
+        bool empty()
         {
-            m_FlatCombining.wait_while_combining();
-            return m_Deque.empty();
+            fc_record * pRec = m_FlatCombining.acquire_record();
+
+            if ( c_bEliminationEnabled )
+                m_FlatCombining.batch_combine( op_empty, pRec, *this );
+            else
+                m_FlatCombining.combine( op_empty, pRec, *this );
+
+            assert( pRec->is_done() );
+            m_FlatCombining.release_record( pRec );
+            return pRec->bEmpty;
         }
 
         /// Internal statistics
@@ -393,6 +402,9 @@ namespace cds { namespace container {
                 while ( !m_Deque.empty() )
                     m_Deque.pop_front();
                 break;
+            case op_empty:
+                pRec->bEmpty = m_Deque.empty();
+                break;
             default:
                 assert(false);
                 break;
index 2e56f561e5376a442ceddc8da3f1e15b3fad0578..c98f155b57a7b01052273e785c6260fa2ab801df 100644 (file)
@@ -111,7 +111,8 @@ namespace cds { namespace container {
             op_push = cds::algo::flat_combining::req_Operation,
             op_push_move,
             op_pop,
-            op_clear
+            op_clear,
+            op_empty
         };
 
         // Flat combining publication list record
@@ -231,10 +232,14 @@ namespace cds { namespace container {
         /**
             If the combining is in process the function waits while combining done.
         */
-        bool empty() const
+        bool empty()
         {
-            m_FlatCombining.wait_while_combining();
-            return m_PQueue.empty();
+            fc_record * pRec = m_FlatCombining.acquire_record();
+
+            m_FlatCombining.combine( op_empty, pRec, *this );
+            assert( pRec->is_done() );
+            m_FlatCombining.release_record( pRec );
+            return pRec->bEmpty;
         }
 
         /// Internal statistics
@@ -275,6 +280,9 @@ namespace cds { namespace container {
                 while ( !m_PQueue.empty() )
                     m_PQueue.pop();
                 break;
+            case op_empty:
+                pRec->bEmpty = m_PQueue.empty();
+                break;
             default:
                 assert(false);
                 break;
index bc7b684b22e70e0b8e958a583ace41e7fa1f96aa..8c16dd62eafeb58c28fc58c52a22e9ce7347ea2a 100644 (file)
@@ -117,9 +117,10 @@ namespace cds { namespace container {
         /// Queue operation IDs
         enum fc_operation {
             op_enq = cds::algo::flat_combining::req_Operation, ///< Enqueue
-            op_enq_move,   ///< Enqueue (move semantics)
+            op_enq_move,    ///< Enqueue (move semantics)
             op_deq,         ///< Dequeue
-            op_clear        ///< Clear
+            op_clear,       ///< Clear
+            op_empty        ///< Empty
         };
 
         /// Flat combining publication list record
@@ -266,10 +267,18 @@ namespace cds { namespace container {
         /**
             If the combining is in process the function waits while combining done.
         */
-        bool empty() const
+        bool empty()
         {
-            m_FlatCombining.wait_while_combining();
-            return m_Queue.empty();
+            fc_record * pRec = m_FlatCombining.acquire_record();
+
+            if ( c_bEliminationEnabled )
+                m_FlatCombining.batch_combine( op_empty, pRec, *this );
+            else
+                m_FlatCombining.combine( op_empty, pRec, *this );
+
+            assert( pRec->is_done() );
+            m_FlatCombining.release_record( pRec );
+            return pRec->bEmpty;
         }
 
         /// Internal statistics
@@ -311,6 +320,9 @@ namespace cds { namespace container {
                 while ( !m_Queue.empty() )
                     m_Queue.pop();
                 break;
+            case op_empty:
+                pRec->bEmpty = m_Queue.empty();
+                break;
             default:
                 assert(false);
                 break;
index 3d3d5e4df05620ac1c9134e84a93a26ced499fc4..661983ef69bea1ea63a96e76ce7098e820ffb6f4 100644 (file)
@@ -117,7 +117,8 @@ namespace cds { namespace container {
             op_push = cds::algo::flat_combining::req_Operation, ///< Push
             op_push_move,   ///< Push (move semantics)
             op_pop,         ///< Pop
-            op_clear        ///< Clear
+            op_clear,       ///< Clear
+            op_empty        ///< Empty
         };
 
         /// Flat combining publication list record
@@ -244,10 +245,18 @@ namespace cds { namespace container {
         /**
             If the combining is in process the function waits while combining done.
         */
-        bool empty() const
+        bool empty()
         {
-            m_FlatCombining.wait_while_combining();
-            return m_Stack.empty();
+            fc_record * pRec = m_FlatCombining.acquire_record();
+
+            if ( c_bEliminationEnabled )
+                m_FlatCombining.batch_combine( op_empty, pRec, *this );
+            else
+                m_FlatCombining.combine( op_empty, pRec, *this );
+
+            assert( pRec->is_done() );
+            m_FlatCombining.release_record( pRec );
+            return pRec->bEmpty;
         }
 
         /// Internal statistics
@@ -290,6 +299,9 @@ namespace cds { namespace container {
                 while ( !m_Stack.empty() )
                     m_Stack.pop();
                 break;
+            case op_empty:
+                pRec->bEmpty = m_Stack.empty();
+                break;
             default:
                 assert(false);
                 break;