1 // tagged pointer, for aba prevention
3 // Copyright (C) 2008 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/lockfree/detail/branch_hints.hpp>
22 class BOOST_LOCKFREE_DCAS_ALIGNMENT tagged_ptr
25 typedef std::size_t tag_t;
27 /** uninitialized constructor */
28 tagged_ptr(void) BOOST_NOEXCEPT//: ptr(0), tag(0)
31 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
32 tagged_ptr(tagged_ptr const & p):
33 ptr(p.ptr), tag(p.tag)
36 tagged_ptr(tagged_ptr const & p) = default;
39 explicit tagged_ptr(T * p, tag_t t = 0):
43 /** unsafe set operation */
45 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
46 tagged_ptr & operator= (tagged_ptr const & p)
52 tagged_ptr & operator= (tagged_ptr const & p) = default;
55 void set(T * p, tag_t t)
62 /** comparing semantics */
64 bool operator== (volatile tagged_ptr const & p) const
66 return (ptr == p.ptr) && (tag == p.tag);
69 bool operator!= (volatile tagged_ptr const & p) const
71 return !operator==(p);
77 T * get_ptr(void) const
95 tag_t get_next_tag() const
97 tag_t next = (get_tag() + 1) & (std::numeric_limits<tag_t>::max)();
101 void set_tag(tag_t t)
107 /** smart pointer support */
109 T & operator*() const
114 T * operator->() const
119 operator bool(void) const
130 } /* namespace detail */
131 } /* namespace lockfree */
132 } /* namespace boost */
134 #endif /* BOOST_LOCKFREE_TAGGED_PTR_DCAS_HPP_INCLUDED */