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_LINEAR_MUTEX_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_LINEAR_MUTEX_H
16 #include <junction/Core.h>
17 #include <junction/SingleMap_Linear.h>
18 #include <turf/Mutex.h>
19 #include <turf/Util.h>
26 static TURF_CONSTEXPR const char* MapName = "Single + Mutex";
33 ThreadContext(MapAdapter&, ureg) {
36 void registerThread() {
39 void unregisterThread() {
49 SingleMap_Linear<u32, void*> m_map;
52 Map(ureg capacity) : m_map(capacity) {
55 void assign(u32 key, void* value) {
56 turf::LockGuard<turf::Mutex> guard(m_mutex);
57 m_map.assign(key, value);
61 turf::LockGuard<turf::Mutex> guard(m_mutex);
62 return m_map.get(key);
65 void* erase(u32 key) {
66 turf::LockGuard<turf::Mutex> guard(m_mutex);
67 return m_map.erase(key);
71 static ureg getInitialCapacity(ureg maxPopulation) {
72 return turf::util::roundUpPowerOf2(maxPopulation / 4);
77 } // namespace junction
79 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_LINEAR_MUTEX_H