Line data Source code
1 : /** 2 : Copyright (c) 2020-2022 Roman Katuntsev <sbkarr@stappler.org> 3 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 4 : 5 : Permission is hereby granted, free of charge, to any person obtaining a copy 6 : of this software and associated documentation files (the "Software"), to deal 7 : in the Software without restriction, including without limitation the rights 8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 : copies of the Software, and to permit persons to whom the Software is 10 : furnished to do so, subject to the following conditions: 11 : 12 : The above copyright notice and this permission notice shall be included in 13 : all copies or substantial portions of the Software. 14 : 15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 : THE SOFTWARE. 22 : **/ 23 : 24 : #ifndef STAPPLER_CORE_MEMORY_POOL_SPMEMPOOLCONFIG_H_ 25 : #define STAPPLER_CORE_MEMORY_POOL_SPMEMPOOLCONFIG_H_ 26 : 27 : #include "SPCore.h" 28 : 29 : namespace STAPPLER_VERSIONIZED stappler::mempool::apr { 30 : #if MODULE_STAPPLER_APR 31 : static constexpr int SP_APR_COMPATIBLE = 1; 32 : #else 33 : static constexpr int SP_APR_COMPATIBLE = 0; 34 : #endif 35 : } 36 : 37 : namespace STAPPLER_VERSIONIZED stappler::memory { 38 : 39 : template <typename Sig> 40 : class function; 41 : 42 : } 43 : 44 : 45 : namespace STAPPLER_VERSIONIZED stappler::mempool::custom { 46 : 47 : using Status = int; 48 : 49 : // minimal size of block, that can be reallocated 50 : static constexpr uint32_t BlockThreshold = 256; 51 : 52 : // Align on a power of 2 boundary 53 27732140 : static constexpr size_t SPALIGN(size_t size, uint32_t boundary) { return math::align<size_t>(size, boundary); } 54 : 55 : // Default alignment, 16-bytes is compatible with SSE or other 128-bit SIMD 56 26093072 : static constexpr size_t SPALIGN_DEFAULT(size_t size) { return SPALIGN(size, 16); } 57 : 58 : static constexpr uint32_t BOUNDARY_INDEX ( 12 ); 59 : static constexpr uint32_t BOUNDARY_SIZE ( 1 << BOUNDARY_INDEX ); 60 : 61 : static constexpr uint32_t MIN_ALLOC (2 * BOUNDARY_SIZE); 62 : static constexpr uint32_t MAX_INDEX ( 20 ); 63 : static constexpr uint32_t ALLOCATOR_MAX_FREE_UNLIMITED ( 0 ); 64 : 65 : // address space (not actual mem) reservation for mmap allocator 66 : // you can not allocate more then this with mmap 67 : static constexpr size_t ALLOCATOR_MMAP_RESERVED = size_t(64_GiB); 68 : 69 : static constexpr Status SUCCESS = 0; 70 : 71 : static constexpr uint64_t POOL_MAGIC = 0xDEAD7fffDEADBEEF; 72 : 73 : enum class PoolFlags { 74 : None = 0, 75 : ThreadSafePool = 1 | 2, 76 : ThreadSafeAllocator = 2, 77 : Custom = apr::SP_APR_COMPATIBLE ? 4 : 0, 78 : 79 : Default = ThreadSafeAllocator, 80 : }; 81 : 82 : SP_DEFINE_ENUM_AS_MASK(PoolFlags) 83 : 84 : } 85 : 86 : #endif /* STAPPLER_CORE_MEMORY_POOL_SPMEMPOOLCONFIG_H_ */