QuantumLibrary
quantum_allocator_traits.h
1 /*
2 ** Copyright 2018 Bloomberg Finance L.P.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 #ifndef BLOOMBERG_QUANTUM_ALLOCATOR_TRAITS_H
17 #define BLOOMBERG_QUANTUM_ALLOCATOR_TRAITS_H
18 
19 #include <cstdint>
20 
21 namespace Bloomberg {
22 namespace quantum {
23 
24 #ifndef __QUANTUM_DEFAULT_POOL_ALLOC_SIZE
25  #ifdef __QUANTUM_DEFAULT_STACK_ALLOC_SIZE
26  #warning Deprecated : use __QUANTUM_DEFAULT_POOL_ALLOC_SIZE instead.
27  #define __QUANTUM_DEFAULT_POOL_ALLOC_SIZE __QUANTUM_DEFAULT_STACK_ALLOC_SIZE
28  #else
29  #define __QUANTUM_DEFAULT_POOL_ALLOC_SIZE 1000
30  #endif
31 #endif
32 
33 #ifndef __QUANTUM_DEFAULT_CORO_POOL_ALLOC_SIZE
34  #define __QUANTUM_DEFAULT_CORO_POOL_ALLOC_SIZE 200
35 #endif
36 
37 #ifndef __QUANTUM_FUNCTION_ALLOC_SIZE
38  #define __QUANTUM_FUNCTION_ALLOC_SIZE 128
39 #endif
40 
41 //==============================================================================================
42 // struct AllocatorTraits
43 //==============================================================================================
47  using size_type = uint16_t;
48 
54  static bool& useDefaultAllocator() {
55 #ifdef __QUANTUM_USE_DEFAULT_ALLOCATOR
56  static bool value = true;
57 #else
58  static bool value = false;
59 #endif
60  return value;
61  }
62 
68  static bool& useDefaultCoroAllocator() {
69 #ifdef __QUANTUM_USE_DEFAULT_CORO_ALLOCATOR
70  static bool value = true;
71 #else
72  static bool value = false;
73 #endif
74  return value;
75  }
76 
82  static bool& allocatePoolFromHeap() {
83 #ifdef __QUANTUM_ALLOCATE_POOL_FROM_HEAP
84  static bool value = true;
85 #else
86  static bool value = false;
87 #endif
88  return value;
89  }
90 
96  static size_type size = __QUANTUM_DEFAULT_POOL_ALLOC_SIZE;
97  return size;
98  }
99 
105  static size_type size = __QUANTUM_DEFAULT_CORO_POOL_ALLOC_SIZE;
106  return size;
107  }
108 
115  static size_type size = defaultPoolAllocSize();
116  return size;
117  }
118 
125  static size_type size = defaultPoolAllocSize();
126  return size;
127  }
128 
135  static size_type size = defaultPoolAllocSize();
136  return size;
137  }
138 
145  static size_type size = defaultPoolAllocSize();
146  return size;
147  }
148 
155  static size_type size = defaultPoolAllocSize();
156  return size;
157  }
158 
165  static size_type size = defaultPoolAllocSize();
166  return size;
167  }
168 };
169 
170 }}
171 
172 #endif //BLOOMBERG_QUANTUM_ALLOCATOR_TRAITS_H
static size_type & ioTaskAllocSize()
Get/set if the default size for IO task object pools.
Definition: quantum_allocator_traits.h:154
Definition: quantum_buffer_impl.h:22
static size_type & defaultPoolAllocSize()
Get/set if the default size for internal object pools (other than coroutine stacks).
Definition: quantum_allocator_traits.h:95
static size_type & taskAllocSize()
Get/set if the default size for task object pools.
Definition: quantum_allocator_traits.h:144
uint16_t size_type
Definition: quantum_allocator_traits.h:47
static bool & allocatePoolFromHeap()
Get/set if the allocator pool for internal objects should use the heap or the application stack.
Definition: quantum_allocator_traits.h:82
static size_type & futureAllocSize()
Get/set if the default size for future object pools.
Definition: quantum_allocator_traits.h:124
static size_type & contextAllocSize()
Get/set if the default size for context object pools.
Definition: quantum_allocator_traits.h:134
static size_type & defaultCoroPoolAllocSize()
Get/set if the default size for coroutine stack pools.
Definition: quantum_allocator_traits.h:104
static bool & useDefaultAllocator()
Get/set if the system allocator should be used for internal objects (other than coroutine stacks).
Definition: quantum_allocator_traits.h:54
static size_type & promiseAllocSize()
Get/set if the default size for promise object pools.
Definition: quantum_allocator_traits.h:114
Allows application-wide settings for the various allocators used by Quantum.
Definition: quantum_allocator_traits.h:46
static bool & useDefaultCoroAllocator()
Get/set if the system allocator should be used for coroutine stacks.
Definition: quantum_allocator_traits.h:68
static size_type & queueListAllocSize()
Get/set if the default size for task queue pools.
Definition: quantum_allocator_traits.h:164