Tervel  1.0.0
A collection of wait-free containers and algorithms.
wf_vector_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_VECTOR_API_H_
28 #define WF_VECTOR_API_H_
29 #include <string>
30 
31 #include <tervel/containers/wf/vector/vector.hpp>
32 #include <tervel/util/info.h>
34 #include <tervel/util/tervel.h>
37 
38 template<typename T>
39 class TestClass {
40  public:
41  TestClass(size_t num_threads, size_t capacity) {
42  tervel_obj = new tervel::Tervel(num_threads);
43  attach_thread();
44  container = new tervel::containers::wf::vector::Vector<T>(capacity);
45  }
46 
47  std::string toString() {
48  return "WF Vector";
49  };
50 
51  void attach_thread() {
52  tervel::ThreadContext* thread_context __attribute__((unused));
53  thread_context = new tervel::ThreadContext(tervel_obj);
54  };
55 
56  void detach_thread() {};
57 
58  bool at(size_t idx, T &value) {
59  return container->at(idx, value);
60  };
61 
62  bool cas(size_t idx, T &expValue, T newValue) {
63  return container->cas(idx, expValue, newValue);
64  };
65 
66  size_t push_back(T value) {
67  // return container->push_back_only(value);
68  return container->push_back(value);
69  };
70 
71  bool pop_back(T &value) {
72  return container->pop_back(value);
73  };
74 
75  size_t size() {
76  return container->size();
77  };
78 
79  private:
81  tervel::containers::wf::vector::Vector<T> *container;
82 };
83 
84 #endif // WF_VECTOR_API_H_
void detach_thread()
Definition: wf_vector_api.h:56
Thread local information.
Definition: thread_context.h:62
bool pop_back(T &value)
Definition: wf_vector_api.h:71
map_t * container
Definition: cliff_api.h:102
bool cas(size_t idx, T &expValue, T newValue)
Definition: wf_vector_api.h:62
void attach_thread()
Definition: blank_api.h:40
size_t push_back(T value)
Definition: wf_vector_api.h:66
Contains shared information that should be accessible by all threads.
Definition: tervel.h:39
size_t size()
Definition: wf_vector_api.h:75
tervel::containers::wf::vector::Vector< T > * container
Definition: wf_vector_api.h:81
bool at(size_t idx, T &value)
Definition: wf_vector_api.h:58
Definition: blank_api.h:31
TestClass(size_t num_threads, size_t capacity)
Definition: wf_vector_api.h:41
tervel::Tervel * tervel_obj
Definition: wf_hashmap_api.h:98
std::string toString()
Definition: wf_vector_api.h:47