Tervel  1.0.0
A collection of wait-free containers and algorithms.
vector_array.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 #ifndef __TERVEL_CONTAINERS_WF_VECTOR_VECTOR_ARRAY_H
26 #define __TERVEL_CONTAINERS_WF_VECTOR_VECTOR_ARRAY_H
27 
28 #include <tervel/util/info.h>
29 #include <tervel/util/descriptor.h>
31 
32 namespace tervel {
33 namespace containers {
34 namespace wf {
35 namespace vector {
36 
37 template<typename T>
38 class VectorArray {
39  public:
40  explicit VectorArray() {}
41  explicit VectorArray(size_t capacity) {}
42  virtual ~VectorArray() {}
43 
50  virtual std::atomic<T> * get_spot(const size_t raw_pos,
51  const bool no_add = false) = 0;
52 
53  virtual bool is_valid(T value) {
54  uint64_t val = uint64_t(value);
55  val = val & uint64_t(0x3);
56  return val == uint64_t(0);
57  }
58 
65  virtual bool is_descriptor(T &expected, std::atomic<T> *spot) {
66  void *temp = reinterpret_cast<void *>(expected);
68  /* It is some other threads operation, so lets complete it.*/
69 
70  std::atomic<void *> *temp2 =
71  reinterpret_cast<std::atomic<void *> *>(spot);
72  expected = reinterpret_cast<T>(util::memory::rc::remove_descriptor(temp,
73  temp2));
74  return true;
75  }
76  return false;
77  }
78 }; // class Vector Array
79 } // namespace vector
80 } // namespace wf
81 } // namespace containers
82 } // namespace tervel
83 #endif // __TERVEL_CONTAINERS_WF_VECTOR_VECTOR_ARRAY_H
VectorArray()
Definition: vector_array.h:40
TODO(steven):
Definition: mcas.h:36
VectorArray(size_t capacity)
Definition: vector_array.h:41
virtual bool is_descriptor(T &expected, std::atomic< T > *spot)
Overridden by SingleArray model to detect resize.
Definition: vector_array.h:65
Definition: vector_array.h:38
bool is_descriptor_first(void *descr)
This returns whether or not the least significant bit holds a bitmark.
Definition: descriptor_util.h:189
virtual bool is_valid(T value)
Definition: vector_array.h:53
void * remove_descriptor(void *expected, std::atomic< void * > *address)
This method is used to remove a descriptor object that is conflict with another threads operation...
Definition: descriptor_util.h:208
virtual std::atomic< T > * get_spot(const size_t raw_pos, const bool no_add=false)=0
This function returns the address of the specified position.
virtual ~VectorArray()
Definition: vector_array.h:42