Tervel  1.0.0
A collection of wait-free containers and algorithms.
pool_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_MEMORY_RC_POOL_MANAGER_H_
26 #define TERVEL_MEMORY_RC_POOL_MANAGER_H_
27 
28 
29 #include <tervel/util/info.h>
30 #include <tervel/util/util.h>
31 #include <tervel/util/system.h>
32 #include <tervel/util/descriptor.h>
35 
36 namespace tervel {
37 namespace util {
38 namespace memory {
39 namespace rc {
40 
41 class DescriptorPool;
42 class PoolElement;
43 
54 class PoolManager {
55  public:
56  friend class DescriptorPool;
57 
64  explicit PoolManager(size_t number_pools)
65  : number_pools_(number_pools)
66  , pools_(new ManagedPool[number_pools]) {}
67 
68  ~PoolManager();
69 
81  DescriptorPool * allocate_pool(const uint64_t tid);
82 
95  void get_safe_elements(PoolElement **pool, uint64_t *count, uint64_t min_elem);
96 
107  void add_safe_elements(uint64_t pid, PoolElement *pool,
108  PoolElement *pool_end = nullptr);
109 
118  void add_unsafe_elements(uint64_t pid, PoolElement *pool);
119 
120 
121  const size_t number_pools_;
122 
123  private:
124  struct ManagedPool {
125  std::atomic<PoolElement *> safe_pool {nullptr};
126  std::atomic<PoolElement *> unsafe_pool {nullptr};
127 
128  char padding[CACHE_LINE_SIZE - sizeof(safe_pool) - sizeof(unsafe_pool)];
129  };
130  static_assert(sizeof(ManagedPool) == CACHE_LINE_SIZE,
131  "Managed pools have to be cache aligned to prevent false sharing.");
132 
133  std::unique_ptr<ManagedPool[]> pools_;
134 
136 };
137 
138 } // namespace rc
139 } // namespace memory
140 } // namespace util
141 } // namespace tervel
142 
143 #endif // TERVEL_MEMORY_RC_POOL_MANAGER_H_
A manager class for the reference count protected memory pools.
Definition: pool_manager.h:54
std::unique_ptr< ManagedPool[]> pools_
Definition: pool_manager.h:131
std::atomic< PoolElement * > unsafe_pool
Definition: pool_manager.h:126
void add_unsafe_elements(uint64_t pid, PoolElement *pool)
Places unsafe elements into the global pool.
TODO(steven):
Definition: mcas.h:36
std::atomic< PoolElement * > safe_pool
Definition: pool_manager.h:125
void add_safe_elements(uint64_t pid, PoolElement *pool, PoolElement *pool_end=nullptr)
Places excess elements into the global pool.
#define CACHE_LINE_SIZE
Definition: system.h:41
void get_safe_elements(PoolElement **pool, uint64_t *count, uint64_t min_elem)
This fuinction attempts to get 'count' many elements from the global pool.
This class is used to hold the memory management information (Header) and a descriptor object...
Definition: pool_element.h:46
char padding[CACHE_LINE_SIZE-sizeof(safe_pool)-sizeof(unsafe_pool)]
Definition: pool_manager.h:128
DescriptorPool * allocate_pool(const uint64_t tid)
Allocates a pool for thread-local use.
Defines a pool of descriptor objects which is used to allocate descriptors and to store them while th...
Definition: descriptor_pool.h:57
const size_t number_pools_
Definition: pool_manager.h:121
PoolManager(size_t number_pools)
PoolManager constructor.
Definition: pool_manager.h:64