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_FOLLY_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_FOLLY_H
16 #include <junction/Core.h>
18 #if !JUNCTION_WITH_FOLLY
19 #error "You must configure with JUNCTION_WITH_FOLLY=1!"
22 #include <folly/AtomicHashMap.h>
29 static TURF_CONSTEXPR const char* MapName = "Folly AtomicHashMap";
36 ThreadContext(MapAdapter&, ureg) {
39 void registerThread() {
42 void unregisterThread() {
51 folly::AtomicHashMap<u32, void*> m_map;
54 Map(ureg capacity) : m_map(capacity) {
57 void insert(u32 key, void* value) {
58 m_map.insert(std::make_pair(key, value));
62 auto ret = m_map.find(key);
63 return ret != m_map.end() ? ret->second : NULL;
71 static ureg getInitialCapacity(ureg maxPopulation) {
72 return maxPopulation / 4;
77 } // namespace junction
79 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_FOLLY_H