1 // tagged pointer, for aba prevention
3 // Copyright (C) 2008, 2016 Tim Blechmann
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_LOCKFREE_TAGGED_PTR_DCAS_HPP_INCLUDED
10 #define BOOST_LOCKFREE_TAGGED_PTR_DCAS_HPP_INCLUDED
12 #include <cstddef> /* for std::size_t */
15 #include <boost/predef.h>
25 #if BOOST_COMP_MSVC && BOOST_ARCH_X86_64
27 #elif BOOST_COMP_MSVC && BOOST_ARCH_X86_32
30 BOOST_ALIGNMENT(2 * sizeof(void*))
35 typedef std::size_t tag_t;
37 /** uninitialized constructor */
38 tagged_ptr(void) BOOST_NOEXCEPT//: ptr(0), tag(0)
41 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
42 tagged_ptr(tagged_ptr const & p):
43 ptr(p.ptr), tag(p.tag)
46 tagged_ptr(tagged_ptr const & p) = default;
49 explicit tagged_ptr(T * p, tag_t t = 0):
53 /** unsafe set operation */
55 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
56 tagged_ptr & operator= (tagged_ptr const & p)
62 tagged_ptr & operator= (tagged_ptr const & p) = default;
65 void set(T * p, tag_t t)
72 /** comparing semantics */
74 bool operator== (volatile tagged_ptr const & p) const
76 return (ptr == p.ptr) && (tag == p.tag);
79 bool operator!= (volatile tagged_ptr const & p) const
81 return !operator==(p);
87 T * get_ptr(void) const
100 tag_t get_tag() const
105 tag_t get_next_tag() const
107 tag_t next = (get_tag() + 1) & (std::numeric_limits<tag_t>::max)();
111 void set_tag(tag_t t)
117 /** smart pointer support */
119 T & operator*() const
124 T * operator->() const
129 operator bool(void) const
140 } /* namespace detail */
141 } /* namespace lockfree */
142 } /* namespace boost */
144 #endif /* BOOST_LOCKFREE_TAGGED_PTR_DCAS_HPP_INCLUDED */