Tervel  1.0.0
A collection of wait-free containers and algorithms.
list_manager.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_LIST_MANAGER_H_
26 #define TERVEL_UTIL_MEMORY_HP_LIST_MANAGER_H_
27 
28 #include <atomic>
29 #include <memory>
30 #include <utility>
31 
32 #include <assert.h>
33 #include <stdint.h>
34 
35 
36 #include <tervel/util/info.h>
37 #include <tervel/util/util.h>
38 #include <tervel/util/system.h>
39 
42 
43 
44 
45 namespace tervel {
46 namespace util {
47 namespace memory {
48 namespace hp {
49 
50 class ElementList;
51 class Element;
52 
58 class ListManager {
59  public:
60  explicit ListManager(size_t number_pools)
61  : free_lists_(new ManagedPool[number_pools])
62  , number_pools_(number_pools) {}
63 
64  ~ListManager();
65 
67  return new ElementList(this);
68  }
69 
70  private:
71  struct ManagedPool {
72  std::atomic<Element *> element_list_ {nullptr};
73  };
74 
82  void recieve_element_list(uint64_t tid, Element * element_list) {
83  assert(free_lists_[tid].element_list_.load() == nullptr && "The HP shared free_lists should be empty when this function is called");
84  free_lists_[tid].element_list_.store(element_list);
85  };
86 
87  std::unique_ptr<ManagedPool[]> free_lists_;
88  size_t number_pools_;
89 
90  friend class ElementList;
92 };
93 
94 } // namespace hp
95 } // namespace memory
96 } // namespace util
97 } // namespace tervel
98 #endif // TERVEL_UTIL_MEMORY_HP_LIST_MANAGER_H_
std::atomic< Element * > element_list_
Definition: list_manager.h:72
ElementList * allocate_list()
Definition: list_manager.h:66
ListManager(size_t number_pools)
Definition: list_manager.h:60
TODO(steven):
Definition: mcas.h:36
std::unique_ptr< ManagedPool[]> free_lists_
Definition: list_manager.h:85
This class is used for the creation of Hazard Pointer Protected Objects Objects which extend it have ...
Definition: hp_element.h:53
Encapsulates a shared central 'to free list' between several thread-local lists.
Definition: list_manager.h:58
Defines a list of objects which are stored until they are safe to be freed.
Definition: hp_list.h:56
void recieve_element_list(uint64_t tid, Element *element_list)
This function is called when a thread is detached.
Definition: list_manager.h:82
size_t number_pools_
Definition: list_manager.h:88
friend class ElementList
Definition: list_manager.h:90