6b6dd4a20743e37bb80c495b10b2a12d6c5e6a01
[libcds.git] / cds / gc / hp / details / hp_retired.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_GC_HZP_DETAILS_HP_RETIRED_H
4 #define __CDS_GC_HZP_DETAILS_HP_RETIRED_H
5
6 #include <cds/gc/hp/details/hp_fwd.h>
7 #include <cds/gc/hp/details/hp_type.h>
8
9 #include <cds/details/bounded_array.h>
10
11 namespace cds {
12     namespace gc{ namespace hzp { namespace details {
13
14         /// Retired pointer
15         typedef cds::gc::details::retired_ptr   retired_ptr;
16
17         /// Array of retired pointers
18         /**
19             The vector of retired pointer ready to delete.
20
21             The Hazard Pointer schema is build on thread-static arrays. For each HP-enabled thread the HP manager allocates
22             array of retired pointers. The array belongs to the thread: owner thread writes to the array, other threads
23             just read it.
24         */
25         class retired_vector {
26             /// Underlying vector implementation
27             typedef cds::details::bounded_array<retired_ptr>    retired_vector_impl;
28
29             retired_vector_impl m_arr   ;   ///< the array of retired pointers
30             size_t              m_nSize ;   ///< Current size of \p m_arr
31
32         public:
33             /// Iterator
34             typedef    retired_vector_impl::iterator    iterator;
35
36             /// Constructor
37             retired_vector( const cds::gc::hzp::GarbageCollector& HzpMgr )    ;    // inline
38             ~retired_vector()
39             {}
40
41             /// Vector capacity.
42             /**
43                 The capacity is constant for any thread. It is defined by cds::gc::hzp::GarbageCollector.
44             */
45             size_t capacity() const     { return m_arr.capacity(); }
46
47             /// Current vector size (count of retired pointers in the vector)
48             size_t size() const         { return m_nSize; }
49
50             /// Set vector size. Uses internally
51             void size( size_t nSize )
52             {
53                 assert( nSize <= capacity() );
54                 m_nSize = nSize;
55             }
56
57             /// Pushes retired pointer to the vector
58             void push( const retired_ptr& p )
59             {
60                 assert( m_nSize < capacity() );
61                 m_arr[ m_nSize ] = p;
62                 ++m_nSize;
63             }
64
65             /// Checks if the vector is full (size() == capacity() )
66             bool isFull() const
67             {
68                 return m_nSize >= capacity();
69             }
70
71             /// Begin iterator
72             iterator    begin()    { return m_arr.begin(); }
73             /// End iterator
74             iterator    end()    { return m_arr.begin() +  m_nSize ; }
75
76             /// Clears the vector. After clearing, size() == 0
77             void clear()
78             {
79                 m_nSize = 0;
80             }
81         };
82
83     } } }    // namespace gc::hzp::details
84 }    // namespace cds
85
86 #endif // #ifndef __CDS_GC_HZP_DETAILS_HP_RETIRED_H