3 #ifndef __CDSUNIT_SKIPLIST_PQUEUE_H
4 #define __CDSUNIT_SKIPLIST_PQUEUE_H
6 #include <cds/container/skip_list_set_hp.h>
7 #include <cds/container/skip_list_set_dhp.h>
8 #include <cds/urcu/general_instant.h>
9 #include <cds/urcu/general_buffered.h>
10 #include <cds/urcu/general_threaded.h>
11 #include <cds/urcu/signal_buffered.h>
12 #include <cds/urcu/signal_threaded.h>
13 #include <cds/container/skip_list_set_rcu.h>
17 template <typename GC>
18 struct SkipListPQueue_pop_max
20 template <typename T, typename Set>
21 bool operator()( T& dest, Set& container ) const
23 typename Set::guarded_ptr gp;
24 bool bRet = container.extract_max( gp );
31 template <typename RCU>
32 struct SkipListPQueue_pop_max< cds::urcu::gc<RCU> >
34 template <typename T, typename Set>
35 bool operator()( T& dest, Set& container ) const
37 typename Set::exempt_ptr ep( container.extract_max());
44 template <typename GC>
45 struct SkipListPQueue_pop_min
47 template <typename T, typename Set>
48 bool operator()( T& dest, Set& container ) const
50 typename Set::guarded_ptr gp;
51 bool bRet = container.extract_min( gp );
58 template <typename RCU>
59 struct SkipListPQueue_pop_min< cds::urcu::gc<RCU> >
61 template <typename T, typename Set>
62 bool operator()( T& dest, Set& container ) const
64 typename Set::exempt_ptr ep( container.extract_min());
71 template <typename GC, typename T, typename Traits, bool Max=true>
72 class SkipListPQueue: protected cds::container::SkipListSet< GC, T, Traits >
74 typedef cds::container::SkipListSet< GC, T, Traits > base_class;
76 template <typename GC2> friend struct SkipListPQueue_pop_max;
77 template <typename GC2> friend struct SkipListPQueue_pop_min;
80 bool push( value_type const& val )
82 return base_class::insert( val );
85 bool pop( value_type& dest )
87 return Max ? SkipListPQueue_pop_max< typename base_class::gc >()( dest, *this )
88 : SkipListPQueue_pop_min< typename base_class::gc >()( dest, *this );
98 return base_class::empty();
103 return base_class::size();
106 typename base_class::stat const& statistics() const
108 return base_class::statistics();
112 } // namespace pqueue
114 #endif // #ifndef __CDSUNIT_SKIPLIST_PQUEUE_H