-
Notifications
You must be signed in to change notification settings - Fork 941
Expand file tree
/
Copy pathPoolConfig.h
More file actions
92 lines (78 loc) · 2.9 KB
/
Copy pathPoolConfig.h
File metadata and controls
92 lines (78 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @file PoolConfig.h
*/
#ifndef RTPS_HISTORY_POOLCONFIG_H_
#define RTPS_HISTORY_POOLCONFIG_H_
#include <fastdds/rtps/attributes/HistoryAttributes.h>
#include <fastdds/rtps/attributes/ResourceManagement.hpp>
namespace eprosima {
namespace fastdds {
namespace rtps {
struct BasicPoolConfig
{
//! Memory management policy.
MemoryManagementPolicy_t memory_policy;
//! Payload size when preallocating data.
uint32_t payload_initial_size;
};
struct PoolConfig : public BasicPoolConfig
{
PoolConfig() = default;
constexpr PoolConfig(
MemoryManagementPolicy_t policy,
uint32_t payload_size,
uint32_t ini_size,
uint32_t max_size) noexcept
: BasicPoolConfig {policy, payload_size}
, initial_size(ini_size)
, maximum_size(max_size)
{
}
//! Initial number of elements when preallocating data.
uint32_t initial_size;
//! Maximum number of elements in the pool. Default value is 0, indicating to make allocations until they fail.
uint32_t maximum_size;
/**
* Transform a HistoryAttributes object into a PoolConfig
*
* @param [in] history_attr HistoryAttributes to be transformed
*
* @return equivalent PoolConfig object
*/
static constexpr PoolConfig from_history_attributes(
const HistoryAttributes& history_attr) noexcept
{
return
{
history_attr.memoryPolicy,
history_attr.payloadMaxSize,
// Negative or 0 means no preallocation.
// Otherwise, we need to reserve the extra to avoid dynamic allocations after the pools are created.
static_cast<uint32_t>(
history_attr.initialReservedCaches <= 0 ?
0 : history_attr.initialReservedCaches + history_attr.extraReservedCaches),
// Negative or 0 means infinite maximum.
// Otherwise, we need to allow the extra.
static_cast<uint32_t>(
history_attr.maximumReservedCaches <= 0 ?
0 : history_attr.maximumReservedCaches + history_attr.extraReservedCaches)
};
}
};
} /* namespace rtps */
} /* namespace fastdds */
} /* namespace eprosima */
#endif /* RTPS_HISTORY_POOLCONFIG_H_ */