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_TBB_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_TBB_H
16 #include <junction/Core.h>
18 #if !JUNCTION_WITH_TBB
19 #error "You must configure with JUNCTION_WITH_TBB=1!"
22 #include <tbb/concurrent_hash_map.h>
29 static TURF_CONSTEXPR const char* getMapName() { return "Intel TBB concurrent_hash_map"; }
36 ThreadContext(MapAdapter&, ureg) {
39 void registerThread() {
42 void unregisterThread() {
51 tbb::concurrent_hash_map<u32, void*> m_map;
54 Map(ureg capacity) : m_map(capacity) {
57 void assign(u32 key, void* value) {
58 m_map.insert(std::make_pair(key, value));
62 tbb::concurrent_hash_map<u32, void*>::const_accessor result;
63 if (m_map.find(result, key))
64 return result->second;
74 static ureg getInitialCapacity(ureg maxPopulation) {
75 return maxPopulation / 4;
80 } // namespace junction
82 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_TBB_H