Tervel  1.0.0
A collection of wait-free containers and algorithms.
hp_element.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_UTIL_MEMORY_HP_POOL_ELEMENT_H_
26 #define TERVEL_UTIL_MEMORY_HP_POOL_ELEMENT_H_
27 
28 #include <atomic>
29 #include <utility>
30 
31 #include <assert.h>
32 #include <stdint.h>
33 #include <stddef.h>
34 
35 #include <tervel/util/info.h>
36 #include <tervel/util/util.h>
38 
39 namespace tervel {
40 namespace util {
41 namespace memory {
42 namespace hp {
43 
44 class HazardPointer;
53 class Element {
54  public:
55  Element() {}
56  virtual ~Element() {}
57 
67  void safe_delete(bool no_check = false,
68  ElementList * const element_list = tervel::tl_thread_info->get_hp_element_list()) {
69  #ifdef TERVEL_MEM_HP_NO_FREE
70  return;
71  #endif
72 
73  if (no_check) {
74  this->~Element();
75  } else if (no_check) {
76  delete this;
77  } else {
78  element_list->add_to_unsafe(this);
79  }
80  element_list->try_to_free_elements();
81  }
82 
91  virtual bool on_watch(std::atomic<void *> *address, void *expected) {
92  return true;
93  }
94 
101  virtual bool on_is_watched() {return false;}
106  virtual void on_unwatch() {}
107 
108 
109  private:
113  Element * next() { return next_; }
114 
118  void next(Element *next) { next_ = next; }
119 
120  Element *next_ {nullptr};
121  // void operator delete( void * ) {}
122  friend ListManager;
123  friend ElementList;
125 };
126 
127 } // namespace hp
128 } // namespace memory
129 } // namespace util
130 } // namespace tervel
131 
132 #endif // TERVEL_UTIL_MEMORY_HP_POOL_ELEMENT_H_
virtual void on_unwatch()
This function is used to remove a strong watch on an Element.
Definition: hp_element.h:106
Element * next()
Helper method for getting the next pointer.
Definition: hp_element.h:113
TODO(steven):
Definition: mcas.h:36
This class is used for the creation of Hazard Pointer Protected Objects Objects which extend it have ...
Definition: hp_element.h:53
Element()
Definition: hp_element.h:55
friend ListManager
Definition: hp_element.h:122
Defines a list of objects which are stored until they are safe to be freed.
Definition: hp_list.h:56
__thread ThreadContext * tl_thread_info
friend ElementList
Definition: hp_element.h:123
void safe_delete(bool no_check=false, ElementList *const element_list=tervel::tl_thread_info->get_hp_element_list())
This function is used to free a hazard pointer protected object if it is safe to do so OR add it to a...
Definition: hp_element.h:67
virtual bool on_watch(std::atomic< void * > *address, void *expected)
This function is used to achieve a strong watch on an Element.
Definition: hp_element.h:91
void next(Element *next)
Helper method for setting the next pointer.
Definition: hp_element.h:118
virtual bool on_is_watched()
This function is used to check a strong watch on an Element.
Definition: hp_element.h:101
Element * next_
Definition: hp_element.h:120
virtual ~Element()
Definition: hp_element.h:56