Tervel  1.0.0
A collection of wait-free containers and algorithms.
wf_ringbuffer_api.h
Go to the documentation of this file.
1 /*
2 #The MIT License (MIT)
3 #
4 #Copyright (c) 2015 University of Central Florida's Computer Software Engineering
5 #Scalable & Secure Systems (CSE - S3) Lab
6 #
7 #Permission is hereby granted, free of charge, to any person obtaining a copy
8 #of this software and associated documentation files (the "Software"), to deal
9 #in the Software without restriction, including without limitation the rights
10 #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 #copies of the Software, and to permit persons to whom the Software is
12 #furnished to do so, subject to the following conditions:
13 #
14 #The above copyright notice and this permission notice shall be included in
15 #all copies or substantial portions of the Software.
16 #
17 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 #THE SOFTWARE.
24 #
25 */
26 
27 #ifndef WF_RINGBUFFER_API_H_
28 #define WF_RINGBUFFER_API_H_
29 
30 #include <string>
32 #include <tervel/util/info.h>
34 #include <tervel/util/tervel.h>
37 
38 template<class Value>
39 class TestClass {
40  public:
41  class WrapperType;
42 
44 
46  public:
47  WrapperType(Value x) : x_(x) {};
48  Value value() { return x_; };
49  std::string toString() {
50  // uint64_t x = (thread_id << 56) | loop_count;
51  uint64_t loop = x_ & 0x00FFFFFFFFFFFFFF;
52  uint64_t tid = x_ >> 56;
53  return "TID: " + std::to_string(tid) + " LC: " + std::to_string(loop);
54  }
55  private:
56  const Value x_;
57  };
58 
59  void sanity_check();
60 
61  TestClass(size_t num_threads, size_t capacity) {
62  tervel_obj = new tervel::Tervel(num_threads);
63  attach_thread();
64  container = new container_t(capacity);
65  }
66 
68  std::string temp = container->debug_string();
69  std::cout << temp << std::endl;
70  delete container;
71  }
72 
73  std::string toString() {
74  return "WF RingBuffer";
75  };
76 
77  void attach_thread() {
78  tervel::ThreadContext* thread_context __attribute__((unused));
79  thread_context = new tervel::ThreadContext(tervel_obj);
80  };
81 
82  void detach_thread() {};
83 
84  bool enqueue(Value value) {
85  WrapperType *temp = new WrapperType(value);
86  bool res = container->enqueue(temp);
87  return res;
88  };
89 
90  bool dequeue(Value& value) {
91  WrapperType *temp;
92  bool res = container->dequeue(temp);
93  if (res) {
94  value = temp->value();
95  }
96  return res;
97  };
98 
99  private:
101  container_t *container;
102 };
103 
104 #endif // WF_RINGBUFFER_API_H_
void detach_thread()
Definition: wf_ringbuffer_api.h:82
Thread local information.
Definition: thread_context.h:62
container_t * container
Definition: wf_ringbuffer_api.h:101
WrapperType(Value x)
Definition: wf_ringbuffer_api.h:47
map_t * container
Definition: cliff_api.h:102
bool enqueue(Value value)
Definition: wf_ringbuffer_api.h:84
void sanity_check()
const Value x_
Definition: wf_ringbuffer_api.h:56
void attach_thread()
Definition: blank_api.h:40
This is a non-blocking FIFO ring buffer design that was made wait-free by applying a progress assuran...
Definition: ring_buffer.h:73
Value value()
Definition: wf_ringbuffer_api.h:48
tervel::containers::wf::RingBuffer< WrapperType * > container_t
Definition: wf_ringbuffer_api.h:41
bool dequeue(Value &value)
Definition: wf_ringbuffer_api.h:90
RingBuffer value class, values stored in the class must extend it.
Definition: ring_buffer.h:92
uint64_t Value
Definition: testObject.h:59
Contains shared information that should be accessible by all threads.
Definition: tervel.h:39
std::string toString()
Definition: wf_ringbuffer_api.h:49
Definition: blank_api.h:31
TestClass(size_t num_threads, size_t capacity)
Definition: wf_ringbuffer_api.h:61
Definition: wf_ringbuffer_api.h:45
tervel::Tervel * tervel_obj
Definition: wf_hashmap_api.h:98
~TestClass()
Definition: wf_ringbuffer_api.h:67
std::string toString()
Definition: wf_ringbuffer_api.h:73