Changes libcds library path
[junction.git] / junction / extra / impl / MapAdapter_NBDS.h
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
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 ------------------------------------------------------------------------*/
12
13 #ifndef JUNCTION_EXTRA_IMPL_MAPADAPTER_NBDS_H
14 #define JUNCTION_EXTRA_IMPL_MAPADAPTER_NBDS_H
15
16 #include <junction/Core.h>
17
18 #if !JUNCTION_WITH_NBDS
19 #error "You must configure with JUNCTION_WITH_NBDS=1!"
20 #endif
21
22 extern "C" {
23 #include <runtime.h>
24 #include <rcu.h>
25 #include <../runtime/rlocal.h>
26 #include <hashtable.h>
27 }
28
29 namespace junction {
30 namespace extra {
31
32 class MapAdapter {
33 public:
34     static TURF_CONSTEXPR const char* getMapName() { return "nbds hashtable_t"; }
35
36     MapAdapter(ureg) {
37     }
38
39     class ThreadContext {
40     private:
41         ureg m_threadIndex;
42
43     public:
44         ThreadContext(MapAdapter&, ureg threadIndex) : m_threadIndex(threadIndex) {
45         }
46
47         void registerThread() {
48             rcu_thread_init(m_threadIndex);
49         }
50
51         void unregisterThread() {
52         }
53
54         void update() {
55             rcu_update();
56         }
57     };
58
59     class Map {
60     private:
61         hashtable_t* m_map;
62
63     public:
64         Map(ureg) {
65             m_map = ht_alloc(NULL);
66         }
67
68         ~Map() {
69             ht_free(m_map);
70         }
71
72         void assign(u32 key, void* value) {
73             ht_cas(m_map, key, CAS_EXPECT_WHATEVER, (map_val_t) value);
74         }
75
76         void* get(u32 key) {
77             return (void*) ht_get(m_map, key);
78         }
79
80         void erase(u32 key) {
81             ht_remove(m_map, key);
82         }
83     };
84
85     static ureg getInitialCapacity(ureg) {
86         return 0;
87     }
88 };
89
90 } // namespace extra
91 } // namespace junction
92
93 #endif // JUNCTION_EXTRA_IMPL_MAPADAPTER_NBDS_H