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_STDMAP_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_STDMAP_H
16 #include <junction/Core.h>
25 static TURF_CONSTEXPR const char* getMapName() { return "std::map + std::mutex"; }
32 ThreadContext(MapAdapter&, ureg) {
35 void registerThread() {
38 void unregisterThread() {
48 typedef std::map<u32, void*> MapType;
55 void assign(u32 key, void* value) {
56 std::lock_guard<std::mutex> guard(m_mutex);
61 std::lock_guard<std::mutex> guard(m_mutex);
62 MapType::iterator iter = m_map.find(key);
63 return (iter == m_map.end()) ? NULL : iter->second;
67 std::lock_guard<std::mutex> guard(m_mutex);
74 MapType::iterator m_iter;
77 Iterator(Map& map) : m_map(map), m_iter(m_map.m_map.begin()) {
84 bool isValid() const {
85 return m_iter != m_map.m_map.end();
92 void* getValue() const {
93 return m_iter->second;
98 static ureg getInitialCapacity(ureg) {
104 } // namespace junction
106 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_STDMAP_H