CUBRID Engine  latest
lockedheap.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /*
4 
5  Heap Layers: An Extensible Memory Allocation Infrastructure
6 
7  Copyright (C) 2000-2020 by Emery Berger
8  http://www.emeryberger.com
9  emery@cs.umass.edu
10 
11  Heap Layers is distributed under the terms of the Apache 2.0 license.
12 
13  You may obtain a copy of the License at
14  http://www.apache.org/licenses/LICENSE-2.0
15 
16 */
17 
18 #ifndef HL_LOCKEDHEAP_H
19 #define HL_LOCKEDHEAP_H
20 
21 #include <mutex>
22 #include <cstddef>
23 
24 namespace HL {
25 
26  template <class LockType, class Super>
27  class LockedHeap : public Super {
28  public:
29 
30  enum { Alignment = Super::Alignment };
31 
32  inline void * malloc (size_t sz) {
33  std::lock_guard<LockType> l (thelock);
34  return Super::malloc (sz);
35  }
36 
37  inline void free (void * ptr) {
38  std::lock_guard<LockType> l (thelock);
39  Super::free (ptr);
40  }
41 
42  inline size_t getSize (void * ptr) const {
43  std::lock_guard<LockType> l (thelock);
44  return Super::getSize (ptr);
45  }
46 
47  inline size_t getSize (void * ptr) {
48  std::lock_guard<LockType> l (thelock);
49  return Super::getSize (ptr);
50  }
51 
52  inline void lock() {
53  thelock.lock();
54  }
55 
56  inline void unlock() {
57  thelock.unlock();
58  }
59 
60  private:
61  // char dummy[128]; // an effort to avoid false sharing.
62  LockType thelock;
63  };
64 
65 }
66 
67 #endif
void free(void *ptr)
Definition: lockedheap.h:37
LockType thelock
Definition: lockedheap.h:62
Definition: heaplayers.h:34
void * malloc(size_t sz)
Definition: lockedheap.h:32
size_t getSize(void *ptr) const
Definition: lockedheap.h:42
size_t getSize(void *ptr)
Definition: lockedheap.h:47
void unlock()
Definition: lockedheap.h:56