1 /*------------------------------------------------------------------------
2 Junction: Concurrent data structures in C++
3 Copyright (c) 2016 Jeff Preshing
5 Distributed under the Simplified BSD License.
6 Original location: https://github.com/preshing/junction
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
13 #ifndef JUNCTION_EXTRA_IMPL_MAPADAPTER_CDS_MICHAEL_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_CDS_MICHAEL_H
16 #include <junction/Core.h>
18 #if !JUNCTION_WITH_CDS
19 #error "You must configure with JUNCTION_WITH_CDS=1!"
22 #include <junction/MapTraits.h>
24 #include <cds/gc/hp.h>
25 #include <cds/container/michael_kvlist_hp.h>
26 #include <cds/container/michael_map.h>
33 static TURF_CONSTEXPR const char* getMapName() { return "CDS MichaelKVList"; }
39 m_hpGC = new cds::gc::HP;
49 ThreadContext(MapAdapter&, ureg) {
52 void registerThread() {
53 cds::threading::Manager::attachThread();
56 void unregisterThread() {
57 cds::threading::Manager::detachThread();
66 // List traits based on std::less predicate
67 struct ListTraits : public cds::container::michael_list::traits {
68 typedef std::less<u32> less;
72 typedef cds::container::MichaelKVList<cds::gc::HP, u32, void*, ListTraits> OrderedList;
75 struct MapTraits : public cds::container::michael_map::traits {
77 size_t operator()(u32 i) const {
78 return cds::opt::v::hash<u32>()(i);
83 cds::container::MichaelHashMap<cds::gc::HP, OrderedList, MapTraits> m_map;
86 Map(ureg capacity) : m_map(capacity, 1) {
89 void assign(u32 key, void* value) {
90 m_map.insert(key, value);
95 m_map.find(key, [&result](std::pair<const u32, void*>& item) { result = item.second; });
104 static ureg getInitialCapacity(ureg maxPopulation) {
105 return maxPopulation / 4;
110 } // namespace junction
112 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_CDS_MICHAEL_H