CUBRID Engine  latest
customheaps.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 //
19 // Custom Heap Memory Allocators
20 //
21 
22 #include <stdlib.h>
23 #include <new>
24 
25 #include "porting_inline.hpp"
26 #include "system.h"
27 #include "heaplayers.h"
28 
29 using namespace HL;
30 
31 volatile int anyThreadCreatedInHL = 1;
32 
33 //
34 // Fixed Heap
35 //
36 
37 // class definition
39  public LockedHeap<SpinLockType,FreelistHeap<ZoneHeap<MallocHeap,0> > > {};
40 
41 // initialize & finalize
42 UINTPTR
43 hl_register_fixed_heap (int chunk_size)
44 {
46  if (th)
47  {
48  th->reset (chunk_size);
49  return (UINTPTR) th;
50  }
51  return 0;
52 }
53 
54 void
55 hl_unregister_fixed_heap (UINTPTR heap_id)
56 {
57  TheFixedHeapType *th = (TheFixedHeapType *) heap_id;
58  if (th)
59  {
60  delete th;
61  }
62 }
63 
64 // alloc & free
65 void *
66 hl_fixed_alloc (UINTPTR heap_id, size_t sz)
67 {
68  TheFixedHeapType *th = (TheFixedHeapType *) heap_id;
69  if (th)
70  {
71  return th->malloc (sz);
72  }
73  return NULL;
74 }
75 
76 void
77 hl_fixed_free (UINTPTR heap_id, void *ptr)
78 {
79  TheFixedHeapType *th = (TheFixedHeapType *) heap_id;
80  if (th)
81  {
82  th->free (ptr);
83  }
84 }
85 
86 //
87 // Obstack Heap
88 //
89 
90 // class definition
92  public SizeHeap<ObstackHeap<0,MallocHeap> > {};
93 
94 // initialize & finalize
95 UINTPTR
96 hl_register_ostk_heap (int chunk_size)
97 {
99  if (th)
100  {
101  th->reset (chunk_size);
102  return (UINTPTR) th;
103  }
104  return 0;
105 }
106 
107 void
108 hl_unregister_ostk_heap (UINTPTR heap_id)
109 {
110  TheObstackHeapType *th = (TheObstackHeapType *) heap_id;
111  if (th)
112  {
113  delete th;
114  }
115 }
116 
117 // alloc & free
118 void *
119 hl_ostk_alloc (UINTPTR heap_id, size_t sz)
120 {
121  TheObstackHeapType *th = (TheObstackHeapType *) heap_id;
122  if (th)
123  {
124  return th->malloc (sz);
125  }
126  return NULL;
127 }
128 
129 void
130 hl_ostk_free (UINTPTR heap_id, void *ptr)
131 {
132  TheObstackHeapType *th = (TheObstackHeapType *) heap_id;
133  if (th)
134  {
135  th->free (ptr);
136  }
137 }
138 
void hl_fixed_free(UINTPTR heap_id, void *ptr)
Definition: customheaps.cpp:77
void hl_unregister_ostk_heap(UINTPTR heap_id)
void * hl_fixed_alloc(UINTPTR heap_id, size_t sz)
Definition: customheaps.cpp:66
void free(void *ptr)
Definition: lockedheap.h:37
void reset(const int chkSize)
Definition: obstackheap.h:66
void hl_unregister_fixed_heap(UINTPTR heap_id)
Definition: customheaps.cpp:55
Definition: heaplayers.h:34
void * malloc(size_t sz)
Definition: lockedheap.h:32
#define NULL
Definition: freelistheap.h:34
volatile int anyThreadCreatedInHL
Definition: customheaps.cpp:31
void free(void *ptr)
Definition: sizeheap.h:65
void hl_ostk_free(UINTPTR heap_id, void *ptr)
void * hl_ostk_alloc(UINTPTR heap_id, size_t sz)
UINTPTR hl_register_fixed_heap(int chunk_size)
Definition: customheaps.cpp:43
UINTPTR hl_register_ostk_heap(int chunk_size)
Definition: customheaps.cpp:96
Allocates extra room for the size of an object.
Definition: sizeheap.h:40
void reset(const int chkSize)
Definition: zoneheap.h:68
The master Heap Layers include file.
void * malloc(size_t sz)
Definition: sizeheap.h:58