From: Marsel Galimullin Date: Thu, 7 May 2015 19:49:12 +0000 (+0300) Subject: fixed empy function in flat combiner containers X-Git-Tag: v2.1.0~245^2 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=6fa355b13c372e0a53d27669b10a0c9eb9b9a6b9 fixed empy function in flat combiner containers --- diff --git a/cds/container/fcdeque.h b/cds/container/fcdeque.h index 9d75864a..acdf12ae 100644 --- a/cds/container/fcdeque.h +++ b/cds/container/fcdeque.h @@ -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 @@ -396,6 +405,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; diff --git a/cds/container/fcpriority_queue.h b/cds/container/fcpriority_queue.h index 2e56f561..c98f155b 100644 --- a/cds/container/fcpriority_queue.h +++ b/cds/container/fcpriority_queue.h @@ -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; diff --git a/cds/container/fcqueue.h b/cds/container/fcqueue.h index fedf97ad..ff6635be 100644 --- a/cds/container/fcqueue.h +++ b/cds/container/fcqueue.h @@ -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 @@ -314,6 +323,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; diff --git a/cds/container/fcstack.h b/cds/container/fcstack.h index 7ef2164e..3a2c6815 100644 --- a/cds/container/fcstack.h +++ b/cds/container/fcstack.h @@ -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 @@ -292,6 +301,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;