tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
setadaptor.h
Go to the documentation of this file.
1 #ifndef SETADAPTOR_H
2 #define SETADAPTOR_H
3 
6 #include "rstm/list/rstmlist.hpp"
9 #include "common/allocator.h"
10 #include "ostm/skiplist/stmskip.h"
11 
13 {
14  FIND = 0,
17 };
18 
20 {
21  uint8_t type;
22  uint32_t key;
23 };
24 
26 {
27  LIVE = 0,
30 };
31 
32 typedef std::vector<SetOperator> SetOpArray;
33 
34 template<typename T>
36 {
37 };
38 
39 template<>
41 {
42 public:
43  SetAdaptor(uint64_t cap, uint64_t threadCount, uint32_t transSize)
44  : m_descAllocator(cap * threadCount * TransList::Desc::SizeOf(transSize), threadCount, TransList::Desc::SizeOf(transSize))
45  , m_nodeAllocator(cap * threadCount * sizeof(TransList::Node) * transSize, threadCount, sizeof(TransList::Node))
46  , m_nodeDescAllocator(cap * threadCount * sizeof(TransList::NodeDesc) * transSize, threadCount, sizeof(TransList::NodeDesc))
47  , m_list(&m_nodeAllocator, &m_descAllocator, &m_nodeDescAllocator)
48  { }
49 
50  void Init()
51  {
52  m_descAllocator.Init();
53  m_nodeAllocator.Init();
54  m_nodeDescAllocator.Init();
55  }
56 
57  void Uninit(){}
58 
59  bool ExecuteOps(const SetOpArray& ops)
60  {
61  //TransList::Desc* desc = m_list.AllocateDesc(ops.size());
62  TransList::Desc* desc = m_descAllocator.Alloc();
63  desc->size = ops.size();
64  desc->status = TransList::ACTIVE;
65 
66  for(uint32_t i = 0; i < ops.size(); ++i)
67  {
68  desc->ops[i].type = ops[i].type;
69  desc->ops[i].key = ops[i].key;
70  }
71 
72  return m_list.ExecuteOps(desc);
73  }
74 
75 private:
80 };
81 
82 template<>
84 {
85 public:
86  SetAdaptor(uint64_t cap, uint64_t threadCount, uint32_t transSize)
87  : m_descAllocator(cap * threadCount * Desc::SizeOf(transSize), threadCount, Desc::SizeOf(transSize))
88  , m_nodeDescAllocator(cap * threadCount * sizeof(NodeDesc) * transSize, threadCount, sizeof(NodeDesc))
89  {
90  m_skiplist = transskip_alloc(&m_descAllocator, &m_nodeDescAllocator);
92  }
93 
95  {
96  transskip_free(m_skiplist);
97  }
98 
99  void Init()
100  {
101  m_descAllocator.Init();
102  m_nodeDescAllocator.Init();
103  }
104 
105  void Uninit()
106  {
108  }
109 
110  bool ExecuteOps(const SetOpArray& ops)
111  {
112  //TransList::Desc* desc = m_list.AllocateDesc(ops.size());
113  Desc* desc = m_descAllocator.Alloc();
114  desc->size = ops.size();
115  desc->status = LIVE;
116 
117  for(uint32_t i = 0; i < ops.size(); ++i)
118  {
119  desc->ops[i].type = ops[i].type;
120  desc->ops[i].key = ops[i].key;
121  }
122 
123  return execute_ops(m_skiplist, desc);
124  }
125 
126 private:
130 };
131 
132 
133 template<>
135 {
136 public:
138  {
139  TM_SYS_INIT();
140  }
141 
143  {
144  TM_SYS_SHUTDOWN();
145 
146  printf("Total commit %u, abort (total/fake) %u/%u\n", g_count_commit, g_count_abort, g_count_stm_abort - g_count_abort);
147  }
148 
149  void Init()
150  {
151  TM_THREAD_INIT();
152  }
153 
154  void Uninit()
155  {
157  TM_GET_THREAD();
158 
159  __sync_fetch_and_add(&g_count_stm_abort, tx->num_aborts);
160  }
161 
162  bool ExecuteOps(const SetOpArray& ops) __attribute__ ((optimize (0)))
163  {
164  bool ret = true;
165 
166  TM_BEGIN(atomic)
167  {
168  if(ret == true)
169  {
170  for(uint32_t i = 0; i < ops.size(); ++i)
171  {
172  uint32_t val = ops[i].key;
173  if(ops[i].type == FIND)
174  {
175  ret = m_list.lookup(val TM_PARAM);
176  }
177  else if(ops[i].type == INSERT)
178  {
179  ret = m_list.insert(val TM_PARAM);
180  }
181  else
182  {
183  ret = m_list.remove(val TM_PARAM);
184  }
185 
186  if(ret == false)
187  {
188  //stm::restart();
189  tx->tmabort(tx);
190  break;
191  }
192  }
193  }
194  }
195  TM_END;
196 
197  if(ret)
198  {
200  }
201  else
202  {
204  }
205 
206  return ret;
207  }
208 
209 private:
211 
212  uint32_t g_count_commit = 0;
213  uint32_t g_count_abort = 0;
214  uint32_t g_count_stm_abort = 0;
215 };
216 
217 
218 template<>
220 {
221 public:
223  {
225  m_list = stmskip_alloc();
226  }
227 
229  {
231  }
232 
233  void Init()
234  { }
235 
236  void Uninit()
237  { }
238 
239  bool ExecuteOps(const SetOpArray& ops)
240  {
241  bool ret = stmskip_execute_ops(m_list, (set_op*)ops.data(), ops.size());
242 
243  return ret;
244  }
245 
246 private:
248 };
249 
250 
251 template<>
253 {
254 public:
256  {
257  }
258 
260  {
261  }
262 
263  void Init()
264  {
265  m_list.Init();
266  }
267 
268  void Uninit()
269  {
270  m_list.Uninit();
271  }
272 
273  bool ExecuteOps(const SetOpArray& ops)
274  {
276 
277  for(uint32_t i = 0; i < ops.size(); ++i)
278  {
279  uint32_t key = ops[i].key;
280 
281  if(ops[i].type == FIND)
282  {
283  ret = m_list.Find(key);
284  }
285  else if(ops[i].type == INSERT)
286  {
287  ret = m_list.Insert(key);
288  }
289  else
290  {
291  ret = m_list.Delete(key);
292  }
293 
294  if(ret != BoostingList::OK)
295  {
296  m_list.OnAbort(ret);
297  break;
298  }
299  }
300 
301  if(ret == BoostingList::OK)
302  {
303  m_list.OnCommit();
304  }
305 
306  return ret;
307  }
308 
309 private:
311 };
312 
313 template<>
315 {
316 public:
318 
320 
321  void Init()
322  {
323  m_list.Init();
324  }
325 
326  void Uninit()
327  {
328  m_list.Uninit();
329  }
330 
331  bool ExecuteOps(const SetOpArray& ops)
332  {
334 
335  for(uint32_t i = 0; i < ops.size(); ++i)
336  {
337  uint32_t key = ops[i].key;
338 
339  if(ops[i].type == FIND)
340  {
341  ret = m_list.Find(key);
342  }
343  else if(ops[i].type == INSERT)
344  {
345  ret = m_list.Insert(key);
346  }
347  else
348  {
349  ret = m_list.Delete(key);
350  }
351 
352  if(ret != BoostingSkip::OK)
353  {
354  m_list.OnAbort(ret);
355  break;
356  }
357  }
358 
359  if(ret == BoostingSkip::OK)
360  {
361  m_list.OnCommit();
362  }
363 
364  return ret;
365  }
366 
367 private:
369 };
370 
371 
372 #endif /* end of include guard: SETADAPTOR_H */
bool ExecuteOps(const SetOpArray &ops)
Definition: setadaptor.h:110
Definition: boostinglist.h:33
BoostingList m_list
Definition: setadaptor.h:310
bool set_op ops[]
Definition: stmskip.cc:238
void Init()
Definition: setadaptor.h:233
bool stmskip_execute_ops(stm_skip *l, set_op ops[], int op_size)
Definition: setadaptor.h:29
stm_skip * m_list
Definition: setadaptor.h:247
Definition: setadaptor.h:16
Definition: boostingskip.h:37
bool ExecuteOps(const SetOpArray &ops) __attribute__((optimize(0)))
Definition: setadaptor.h:162
Definition: setadaptor.h:19
Definition: transskip.h:108
#define TM_THREAD_SHUTDOWN()
Definition: library.hpp:292
void Uninit()
Definition: setadaptor.h:326
#define TM_BEGIN(TYPE)
Definition: cxxtm.hpp:34
volatile uint8_t status
Definition: translist.h:47
~SetAdaptor()
Definition: setadaptor.h:259
SetAdaptor()
Definition: setadaptor.h:222
Definition: boostinglist.h:35
Definition: boostinglist.h:10
BoostingSkip m_list
Definition: setadaptor.h:368
Definition: setadaptor.h:15
void transskip_free(trans_skip *l)
Definition: transskip.cc:929
Allocator< NodeDesc > m_nodeDescAllocator
Definition: setadaptor.h:128
Operator ops[]
Definition: transskip.h:83
Definition: rstmlist.hpp:22
RSTMList m_list
Definition: setadaptor.h:210
volatile uint8_t status
Definition: transskip.h:81
SetAdaptor()
Definition: setadaptor.h:255
Allocator< TransList::NodeDesc > m_nodeDescAllocator
Definition: setadaptor.h:78
Definition: setadaptor.h:27
trans_skip * transskip_alloc(Allocator< Desc > *_descAllocator, Allocator< NodeDesc > *_nodeDescAllocator)
Definition: transskip.cc:331
#define TM_END
Definition: cxxtm.hpp:35
void Uninit()
Definition: setadaptor.h:105
~SetAdaptor()
Definition: setadaptor.h:94
uint32_t key
Definition: translist.h:36
static uint32_t g_count_abort
Definition: stmskip.cc:39
Allocator< Desc > m_descAllocator
Definition: setadaptor.h:127
uint8_t size
Definition: translist.h:48
std::vector< SetOperator > SetOpArray
Definition: setadaptor.h:32
void Uninit()
Definition: setadaptor.h:57
class simple_queue __attribute__
void Init()
Definition: setadaptor.h:321
uint32_t key
Definition: transskip.h:71
void destroy_transskip_subsystem(void)
Definition: transskip.cc:809
#define TM_SYS_INIT()
Definition: library.hpp:290
Operator ops[]
Definition: translist.h:49
void Init()
Definition: setadaptor.h:50
SetAdaptor()
Definition: setadaptor.h:317
void init_stmskip_subsystem(void)
Definition: stmskip.cc:289
#define TM_SYS_SHUTDOWN
Definition: library.hpp:293
uint32_t key
Definition: stmskip.h:12
void Uninit()
Definition: setadaptor.h:236
SetOpType
Definition: setadaptor.h:12
static uint32_t g_count_commit
Definition: stmskip.cc:38
SetAdaptor(uint64_t cap, uint64_t threadCount, uint32_t transSize)
Definition: setadaptor.h:43
stm_tx * tx
Definition: stmskip.cc:245
bool ret
Definition: stmskip.cc:242
void init_transskip_subsystem(void)
Definition: transskip.cc:796
bool ExecuteOps(const SetOpArray &ops)
Definition: setadaptor.h:331
#define __sync_fetch_and_add(p, a)
Definition: icc-sync.hpp:57
Definition: translist.h:39
SetOpStatus
Definition: setadaptor.h:25
void stm_skip
Definition: stmskip.h:77
#define TM_PARAM
Definition: cxxtm.hpp:42
ReturnCode
Definition: boostinglist.h:31
~SetAdaptor()
Definition: setadaptor.h:142
void Init()
Definition: setadaptor.h:263
Definition: setadaptor.h:35
~SetAdaptor()
Definition: setadaptor.h:228
#define TM_THREAD_INIT
Definition: library.hpp:291
Definition: transskip.h:74
uint32_t key
Definition: setadaptor.h:22
Definition: setadaptor.h:28
trans_skip * m_skiplist
Definition: setadaptor.h:129
Definition: translist.h:14
SetAdaptor()
Definition: setadaptor.h:137
Definition: boostingskip.h:39
bool ExecuteOps(const SetOpArray &ops)
Definition: setadaptor.h:59
Definition: transskip.h:86
uint8_t size
Definition: transskip.h:82
bool ExecuteOps(const SetOpArray &ops)
Definition: setadaptor.h:239
void Uninit()
Definition: setadaptor.h:268
Definition: stmskip.h:9
TransList m_list
Definition: setadaptor.h:79
bool execute_ops(trans_skip *l, Desc *desc)
Definition: transskip.cc:909
void destory_stmskip_subsystem(void)
Definition: stmskip.cc:300
Definition: translist.h:9
void Init()
Definition: setadaptor.h:99
#define TM_GET_THREAD()
Definition: cxxtm.hpp:39
~SetAdaptor()
Definition: setadaptor.h:319
Allocator< TransList::Desc > m_descAllocator
Definition: setadaptor.h:76
uint8_t type
Definition: transskip.h:70
void Init()
Definition: setadaptor.h:149
Definition: boostingskip.h:13
bool ExecuteOps(const SetOpArray &ops)
Definition: setadaptor.h:273
ReturnCode
Definition: boostingskip.h:35
Allocator< TransList::Node > m_nodeAllocator
Definition: setadaptor.h:77
set_t * stmskip_alloc(void)
Definition: stmskip.cc:121
uint8_t type
Definition: setadaptor.h:21
Definition: setadaptor.h:14
void Uninit()
Definition: setadaptor.h:154
uint8_t type
Definition: translist.h:35
SetAdaptor(uint64_t cap, uint64_t threadCount, uint32_t transSize)
Definition: setadaptor.h:86