[draft] implemented container::MultiLevelHashSet
[libcds.git] / cds / container / fcqueue.h
index ce0301be06a9d08ed15d2433af65d6c5db75558d..ff6635be0724e8523221fb9ae1a4e2d63f110b66 100644 (file)
@@ -1,7 +1,7 @@
 //$$CDS-header$$
 
-#ifndef __CDS_CONTAINER_FCQUEUE_H
-#define __CDS_CONTAINER_FCQUEUE_H
+#ifndef CDSLIB_CONTAINER_FCQUEUE_H
+#define CDSLIB_CONTAINER_FCQUEUE_H
 
 #include <cds/algo/flat_combining.h>
 #include <cds/algo/elimination_opt.h>
@@ -47,7 +47,7 @@ namespace cds { namespace container {
         };
 
         /// FCQueue type traits
-        struct traits: public cds::algo::flat_combining::type_traits
+        struct traits: public cds::algo::flat_combining::traits
         {
             typedef empty_stat      stat;   ///< Internal statistics
             static CDS_CONSTEXPR const bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination"
@@ -56,7 +56,7 @@ namespace cds { namespace container {
         /// Metafunction converting option list to traits
         /**
             \p Options are:
-            - \p opt::lock_type - mutex type, default is \p cds::lock::Spin
+            - \p opt::lock_type - mutex type, default is \p cds::sync::spin
             - \p opt::back_off - back-off strategy, defalt is \p cds::backoff::delay_of<2>
             - \p opt::allocator - allocator type, default is \ref CDS_DEFAULT_ALLOCATOR
             - \p opt::stat - internal statistics, possible type: \p fcqueue::stat, \p fcqueue::empty_stat (the default)
@@ -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
@@ -290,6 +299,9 @@ namespace cds { namespace container {
         {
             assert( pRec );
 
+            // this function is called under FC mutex, so switch TSan off
+            CDS_TSAN_ANNOTATE_IGNORE_RW_BEGIN;
+
             switch ( pRec->op() ) {
             case op_enq:
                 assert( pRec->pValEnq );
@@ -311,16 +323,24 @@ 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;
             }
+            CDS_TSAN_ANNOTATE_IGNORE_RW_END;
         }
 
         /// Batch-processing flat combining
         void fc_process( typename fc_kernel::iterator itBegin, typename fc_kernel::iterator itEnd )
         {
             typedef typename fc_kernel::iterator fc_iterator;
+
+            // this function is called under FC mutex, so switch TSan off
+            CDS_TSAN_ANNOTATE_IGNORE_RW_BEGIN;
+
             for ( fc_iterator it = itBegin, itPrev = itEnd; it != itEnd; ++it ) {
                 switch ( it->op() ) {
                 case op_enq:
@@ -335,6 +355,7 @@ namespace cds { namespace container {
                     break;
                 }
             }
+            CDS_TSAN_ANNOTATE_IGNORE_RW_END;
         }
         //@endcond
 
@@ -381,4 +402,4 @@ namespace cds { namespace container {
     };
 }} // namespace cds::container
 
-#endif // #ifndef __CDS_CONTAINER_FCQUEUE_H
+#endif // #ifndef CDSLIB_CONTAINER_FCQUEUE_H