intrusive MSQueue refactoring (not tested)
[libcds.git] / cds / intrusive / optimistic_queue.h
index eda9ce2092f43e05c18260131c83cebf0860c320..cba41218c80e7de110ea7ef06029754406559138 100644 (file)
@@ -4,12 +4,12 @@
 #define __CDS_INTRUSIVE_OPTIMISTIC_QUEUE_H
 
 #include <type_traits>
-#include <cds/intrusive/base.h>
+#include <functional>   // ref
+#include <cds/intrusive/details/base.h>
 #include <cds/cxx11_atomic.h>
 #include <cds/gc/default_gc.h>
 #include <cds/gc/hrc/gc_fwd.h>
-#include <cds/intrusive/queue_stat.h>
-#include <cds/ref.h>
+#include <cds/intrusive/details/queue_stat.h>
 
 namespace cds { namespace intrusive {
 
@@ -49,10 +49,10 @@ namespace cds { namespace intrusive {
         //@endcond
 
         //@cond
-        template < typename HookType, CDS_DECL_OPTIONS2>
+        template < typename HookType, typename... Options>
         struct hook
         {
-            typedef typename opt::make_options< default_hook, CDS_OPTIONS2>::type  options;
+            typedef typename opt::make_options< default_hook, Options...>::type  options;
             typedef typename options::gc    gc;
             typedef typename options::tag   tag;
             typedef node<gc, tag> node_type;
@@ -66,8 +66,8 @@ namespace cds { namespace intrusive {
             - opt::gc - garbage collector used.
             - opt::tag - tag
         */
-        template < CDS_DECL_OPTIONS2 >
-        struct base_hook: public hook< opt::base_hook_tag, CDS_OPTIONS2 >
+        template < typename... Options >
+        struct base_hook: public hook< opt::base_hook_tag, Options... >
         {};
 
         /// Member hook
@@ -79,8 +79,8 @@ namespace cds { namespace intrusive {
             - opt::gc - garbage collector used.
             - opt::tag - tag
         */
-        template < size_t MemberOffset, CDS_DECL_OPTIONS2 >
-        struct member_hook: public hook< opt::member_hook_tag, CDS_OPTIONS2 >
+        template < size_t MemberOffset, typename... Options >
+        struct member_hook: public hook< opt::member_hook_tag, Options... >
         {
             //@cond
             static const size_t c_nMemberOffset = MemberOffset;
@@ -96,8 +96,8 @@ namespace cds { namespace intrusive {
             - opt::gc - garbage collector used.
             - opt::tag - tag
         */
-        template <typename NodeTraits, CDS_DECL_OPTIONS2 >
-        struct traits_hook: public hook< opt::traits_hook_tag, CDS_OPTIONS2 >
+        template <typename NodeTraits, typename... Options >
+        struct traits_hook: public hook< opt::traits_hook_tag, Options... >
         {
             //@cond
             typedef NodeTraits node_traits;
@@ -117,8 +117,8 @@ namespace cds { namespace intrusive {
             */
             static void is_empty( const node_type * pNode )
             {
-                assert( pNode->m_pNext.load( CDS_ATOMIC::memory_order_relaxed ) == nullptr );
-                assert( pNode->m_pPrev.load( CDS_ATOMIC::memory_order_relaxed ) == nullptr );
+                assert( pNode->m_pNext.load( atomics::memory_order_relaxed ) == nullptr );
+                assert( pNode->m_pPrev.load( atomics::memory_order_relaxed ) == nullptr );
             }
         };
 
@@ -285,7 +285,7 @@ namespace cds { namespace intrusive {
 
         \endcode
     */
-    template <typename GC, typename T, CDS_DECL_OPTIONS9>
+    template <typename GC, typename T, typename... Options>
     class OptimisticQueue
     {
         //@cond
@@ -305,8 +305,8 @@ namespace cds { namespace intrusive {
     public:
         //@cond
         typedef typename opt::make_options<
-            typename cds::opt::find_type_traits< default_options, CDS_OPTIONS9 >::type
-            ,CDS_OPTIONS9
+            typename cds::opt::find_type_traits< default_options, Options... >::type
+            ,Options...
         >::type   options;
 
         typedef typename std::conditional<
@@ -340,9 +340,9 @@ namespace cds { namespace intrusive {
 #endif
 
         /// Rebind template arguments
-        template <typename GC2, typename T2, CDS_DECL_OTHER_OPTIONS9>
+        template <typename GC2, typename T2, typename... Options2>
         struct rebind {
-            typedef OptimisticQueue< GC2, T2, CDS_OTHER_OPTIONS9> other   ;   ///< Rebinding result
+            typedef OptimisticQueue< GC2, T2, Options2...> other   ;   ///< Rebinding result
         };
 
     protected:
@@ -408,7 +408,7 @@ namespace cds { namespace intrusive {
                             fix_list( pTail, pHead );
                             continue;
                         }
-                        if ( m_pHead.compare_exchange_weak( pHead, pFirstNodePrev, memory_model::memory_order_release, CDS_ATOMIC::memory_order_relaxed )) {
+                        if ( m_pHead.compare_exchange_weak( pHead, pFirstNodePrev, memory_model::memory_order_release, atomics::memory_order_relaxed )) {
                             // dequeue success
                             break;
                         }
@@ -490,8 +490,8 @@ namespace cds { namespace intrusive {
         {
             clear();
             node_type * pHead = m_pHead.load(memory_model::memory_order_relaxed);
-            CDS_DEBUG_DO( node_type * pTail = m_pTail.load(memory_model::memory_order_relaxed); )
-            CDS_DEBUG_DO( assert( pHead == pTail ); )
+            CDS_DEBUG_ONLY( node_type * pTail = m_pTail.load(memory_model::memory_order_relaxed); )
+            CDS_DEBUG_ONLY( assert( pHead == pTail ); )
             assert( pHead != nullptr );
 
             m_pHead.store( nullptr, memory_model::memory_order_relaxed );
@@ -513,7 +513,7 @@ namespace cds { namespace intrusive {
             node_type * pTail = guards.protect( 0, m_pTail, node_to_value() )  ;   // Read the tail
             while( true ) {
                 pNew->m_pNext.store( pTail, memory_model::memory_order_release );
-                if ( m_pTail.compare_exchange_strong( pTail, pNew, memory_model::memory_order_release, CDS_ATOMIC::memory_order_relaxed ) ) {     // Try to CAS the tail
+                if ( m_pTail.compare_exchange_strong( pTail, pNew, memory_model::memory_order_release, atomics::memory_order_relaxed ) ) {     // Try to CAS the tail
                     pTail->m_pPrev.store( pNew, memory_model::memory_order_release )     ;           // Success, write prev
                     ++m_ItemCounter;
                     m_Stat.onEnqueue();