2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSUNIT_SKIPLIST_PQUEUE_H
32 #define CDSUNIT_SKIPLIST_PQUEUE_H
34 #include <cds/container/skip_list_set_hp.h>
35 #include <cds/container/skip_list_set_dhp.h>
36 #include <cds/urcu/general_instant.h>
37 #include <cds/urcu/general_buffered.h>
38 #include <cds/urcu/general_threaded.h>
39 #include <cds/urcu/signal_buffered.h>
40 #include <cds/urcu/signal_threaded.h>
41 #include <cds/container/skip_list_set_rcu.h>
45 template <typename GC>
46 struct SkipListPQueue_pop_max
48 template <typename T, typename Set>
49 bool operator()( T& dest, Set& container ) const
51 typename Set::guarded_ptr gp( container.extract_max());
58 template <typename RCU>
59 struct SkipListPQueue_pop_max< 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_max());
71 template <typename GC>
72 struct SkipListPQueue_pop_min
74 template <typename T, typename Set>
75 bool operator()( T& dest, Set& container ) const
77 typename Set::guarded_ptr gp( container.extract_min());
84 template <typename RCU>
85 struct SkipListPQueue_pop_min< cds::urcu::gc<RCU> >
87 template <typename T, typename Set>
88 bool operator()( T& dest, Set& container ) const
90 typename Set::exempt_ptr ep( container.extract_min());
97 template <typename GC, typename T, typename Traits, bool Max=true>
98 class SkipListPQueue: protected cds::container::SkipListSet< GC, T, Traits >
100 typedef cds::container::SkipListSet< GC, T, Traits > base_class;
101 typedef T value_type;
102 template <typename GC2> friend struct SkipListPQueue_pop_max;
103 template <typename GC2> friend struct SkipListPQueue_pop_min;
106 bool push( value_type const& val )
108 return base_class::insert( val );
111 bool pop( value_type& dest )
113 return Max ? SkipListPQueue_pop_max< typename base_class::gc >()( dest, *this )
114 : SkipListPQueue_pop_min< typename base_class::gc >()( dest, *this );
124 return base_class::empty();
129 return base_class::size();
132 typename base_class::stat const& statistics() const
134 return base_class::statistics();
138 } // namespace pqueue
140 #endif // #ifndef CDSUNIT_SKIPLIST_PQUEUE_H