3 #ifndef __CDS_INTRUSIVE_DETAILS_SINGLE_LINK_STRUCT_H
4 #define __CDS_INTRUSIVE_DETAILS_SINGLE_LINK_STRUCT_H
6 #include <cds/intrusive/details/base.h>
7 #include <cds/gc/default_gc.h>
8 #include <cds/cxx11_atomic.h>
10 namespace cds { namespace intrusive {
12 /// Definitions common for single-linked data structures
13 /** @ingroup cds_intrusive_helper
15 namespace single_link {
20 - GC - garbage collector used
21 - Tag - a tag used to distinguish between different implementation
23 template <class GC, typename Tag = opt::none>
26 typedef GC gc ; ///< Garbage collector
27 typedef Tag tag ; ///< tag
29 typedef typename gc::template atomic_ref<node> atomic_node_ptr ; ///< atomic pointer
31 /// Rebind node for other template parameters
32 template <class GC2, typename Tag2 = tag>
34 typedef node<GC2, Tag2> other ; ///< Rebinding result
37 atomic_node_ptr m_pNext ; ///< pointer to the next node in the container
46 typedef cds::gc::default_gc gc;
47 typedef opt::none tag;
52 template < typename HookType, typename... Options>
55 typedef typename opt::make_options< default_hook, Options...>::type options;
56 typedef typename options::gc gc;
57 typedef typename options::tag tag;
58 typedef node<gc, tag> node_type;
59 typedef HookType hook_type;
66 - opt::gc - garbage collector used.
69 template < typename... Options >
70 struct base_hook: public hook< opt::base_hook_tag, Options... >
75 \p MemberOffset defines offset in bytes of \ref node member into your structure.
76 Use \p offsetof macro to define \p MemberOffset
79 - opt::gc - garbage collector used.
82 template < size_t MemberOffset, typename... Options >
83 struct member_hook: public hook< opt::member_hook_tag, Options... >
86 static const size_t c_nMemberOffset = MemberOffset;
92 \p NodeTraits defines type traits for node.
93 See \ref node_traits for \p NodeTraits interface description
96 - opt::gc - garbage collector used.
99 template <typename NodeTraits, typename... Options >
100 struct traits_hook: public hook< opt::traits_hook_tag, Options... >
103 typedef NodeTraits node_traits;
108 template <typename Node>
109 struct link_checker {
111 typedef Node node_type;
114 /// Checks if the link field of node \p pNode is \p nullptr
116 An asserting is generated if \p pNode link field is not \p nullptr
118 static void is_empty( const node_type * pNode )
120 assert( pNode->m_pNext.load( atomics::memory_order_relaxed ) == nullptr );
125 template <class GC, typename Node, opt::link_check_type LinkType >
126 struct link_checker_selector;
128 template <typename GC, typename Node>
129 struct link_checker_selector< GC, Node, opt::never_check_link >
131 typedef intrusive::opt::v::empty_link_checker<Node> type;
134 template <typename GC, typename Node>
135 struct link_checker_selector< GC, Node, opt::debug_check_link >
138 typedef link_checker<Node> type;
140 typedef intrusive::opt::v::empty_link_checker<Node> type;
144 template <typename GC, typename Node>
145 struct link_checker_selector< GC, Node, opt::always_check_link >
147 typedef link_checker<Node> type;
151 /// Metafunction for selecting appropriate link checking policy
152 template < typename Node, opt::link_check_type LinkType >
153 struct get_link_checker
156 typedef typename link_checker_selector< typename Node::gc, Node, LinkType>::type type;
160 } // namespace single_link
162 }} // namespace cds::intrusive
166 #endif // #ifndef __CDS_INTRUSIVE_DETAILS_SINGLE_LINK_STRUCT_H