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>
24 class BOOST_ALIGNMENT(2 * sizeof(void*)) tagged_ptr
27 typedef std::size_t tag_t;
29 /** uninitialized constructor */
30 tagged_ptr(void) BOOST_NOEXCEPT//: ptr(0), tag(0)
33 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
34 tagged_ptr(tagged_ptr const & p):
35 ptr(p.ptr), tag(p.tag)
38 tagged_ptr(tagged_ptr const & p) = default;
41 explicit tagged_ptr(T * p, tag_t t = 0):
45 /** unsafe set operation */
47 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
48 tagged_ptr & operator= (tagged_ptr const & p)
54 tagged_ptr & operator= (tagged_ptr const & p) = default;
57 void set(T * p, tag_t t)
64 /** comparing semantics */
66 bool operator== (volatile tagged_ptr const & p) const
68 return (ptr == p.ptr) && (tag == p.tag);
71 bool operator!= (volatile tagged_ptr const & p) const
73 return !operator==(p);
79 T * get_ptr(void) const
97 tag_t get_next_tag() const
99 tag_t next = (get_tag() + 1) & (std::numeric_limits<tag_t>::max)();
103 void set_tag(tag_t t)
109 /** smart pointer support */
111 T & operator*() const
116 T * operator->() const
121 operator bool(void) const
132 } /* namespace detail */
133 } /* namespace lockfree */
134 } /* namespace boost */
136 #endif /* BOOST_LOCKFREE_TAGGED_PTR_DCAS_HPP_INCLUDED */