9 #ifndef BOOST_LOCKFREE_STACK_HPP_INCLUDED
10 #define BOOST_LOCKFREE_STACK_HPP_INCLUDED
12 #include <boost/checked_delete.hpp>
14 #include <boost/static_assert.hpp>
15 #include <boost/type_traits/is_base_of.hpp>
17 #include <boost/lockfree/detail/tagged_ptr.hpp>
18 #include <boost/lockfree/detail/freelist.hpp>
19 #include <boost/noncopyable.hpp>
27 typename freelist_t = caching_freelist_t,
28 typename Alloc = std::allocator<T>
45 typedef typename Alloc::template rebind<node>::other node_allocator;
48 typedef typename boost::mpl::if_<boost::is_same<freelist_t, caching_freelist_t>,
54 static const bool is_lockfree = node::tagged_ptr::is_lockfree;
60 explicit stack(std::size_t n):
64 bool push(T
const & v)
66 node * newnode = alloc_node(v);
75 newnode->next.set_ptr(old_tos.
get_ptr());
77 while (!tos.
cas(old_tos, newnode));
92 node * new_tos = old_tos->next.
get_ptr();
94 if (tos.
cas(old_tos, new_tos))
97 dealloc_node(old_tos.
get_ptr());
103 bool empty(
void)
const
109 node * alloc_node(T
const & t)
111 node * chunk = pool.allocate();
116 void dealloc_node(node * n)
124 static const int padding_size = 64 -
sizeof(
ptr_type);
126 char padding[padding_size];
bool cas(tagged_ptr const &oldval, T *newptr)
void set(tagged_ptr const &p)