11
11
#include " provider_null.h"
12
12
#include " provider_trace.h"
13
13
14
- using disjoint_params_unique_handle_t =
15
- std::unique_ptr<umf_disjoint_pool_params_t ,
16
- decltype (&umfDisjointPoolParamsDestroy)>;
17
-
18
14
static constexpr size_t DEFAULT_DISJOINT_SLAB_MIN_SIZE = 4096 ;
19
15
static constexpr size_t DEFAULT_DISJOINT_MAX_POOLABLE_SIZE = 4096 ;
20
16
static constexpr size_t DEFAULT_DISJOINT_CAPACITY = 4 ;
21
17
static constexpr size_t DEFAULT_DISJOINT_MIN_BUCKET_SIZE = 64 ;
22
18
23
- disjoint_params_unique_handle_t poolConfig () {
19
+ void * defaultPoolConfig () {
24
20
umf_disjoint_pool_params_handle_t config = nullptr ;
25
21
umf_result_t res = umfDisjointPoolParamsCreate (&config);
26
22
if (res != UMF_RESULT_SUCCESS) {
@@ -50,8 +46,12 @@ disjoint_params_unique_handle_t poolConfig() {
50
46
throw std::runtime_error (" Failed to set min bucket size" );
51
47
}
52
48
53
- return disjoint_params_unique_handle_t (config,
54
- &umfDisjointPoolParamsDestroy);
49
+ return config;
50
+ }
51
+
52
+ umf_result_t poolConfigDestroy (void *config) {
53
+ return umfDisjointPoolParamsDestroy (
54
+ static_cast <umf_disjoint_pool_params_handle_t >(config));
55
55
}
56
56
57
57
using umf_test::test;
@@ -83,17 +83,21 @@ TEST_F(test, freeErrorPropagation) {
83
83
provider_handle = providerUnique.get ();
84
84
85
85
// force all allocations to go to memory provider
86
- disjoint_params_unique_handle_t params = poolConfig ();
87
- umf_result_t retp =
88
- umfDisjointPoolParamsSetMaxPoolableSize (params.get (), 0 );
86
+ umf_disjoint_pool_params_handle_t params;
87
+ umf_result_t retp = umfDisjointPoolParamsCreate (¶ms);
88
+ EXPECT_EQ (retp, UMF_RESULT_SUCCESS);
89
+ retp = umfDisjointPoolParamsSetMaxPoolableSize (params, 0 );
89
90
EXPECT_EQ (retp, UMF_RESULT_SUCCESS);
90
91
91
92
umf_memory_pool_handle_t pool = NULL ;
92
- retp = umfPoolCreate ( umfDisjointPoolOps (), provider_handle, params. get (), 0 ,
93
- &pool);
93
+ retp =
94
+ umfPoolCreate ( umfDisjointPoolOps (), provider_handle, params, 0 , &pool);
94
95
EXPECT_EQ (retp, UMF_RESULT_SUCCESS);
95
96
auto poolHandle = umf_test::wrapPoolUnique (pool);
96
97
98
+ retp = umfDisjointPoolParamsDestroy (params);
99
+ EXPECT_EQ (retp, UMF_RESULT_SUCCESS);
100
+
97
101
static constexpr size_t size = 1024 ;
98
102
void *ptr = umfPoolMalloc (pool, size);
99
103
@@ -130,9 +134,9 @@ TEST_F(test, sharedLimits) {
130
134
static constexpr size_t SlabMinSize = 1024 ;
131
135
static constexpr size_t MaxSize = 4 * SlabMinSize;
132
136
133
- disjoint_params_unique_handle_t config = poolConfig ();
134
- umf_result_t ret =
135
- umfDisjointPoolParamsSetSlabMinSize (config. get () , SlabMinSize);
137
+ umf_disjoint_pool_params_handle_t params =
138
+ ( umf_disjoint_pool_params_handle_t ) defaultPoolConfig ();
139
+ umf_result_t ret = umfDisjointPoolParamsSetSlabMinSize (params , SlabMinSize);
136
140
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
137
141
138
142
auto limits =
@@ -141,24 +145,27 @@ TEST_F(test, sharedLimits) {
141
145
umfDisjointPoolSharedLimitsCreate (MaxSize),
142
146
&umfDisjointPoolSharedLimitsDestroy);
143
147
144
- ret = umfDisjointPoolParamsSetSharedLimits (config. get () , limits.get ());
148
+ ret = umfDisjointPoolParamsSetSharedLimits (params , limits.get ());
145
149
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
146
150
147
151
auto provider =
148
152
wrapProviderUnique (createProviderChecked (&provider_ops, nullptr ));
149
153
150
154
umf_memory_pool_handle_t pool1 = NULL ;
151
155
umf_memory_pool_handle_t pool2 = NULL ;
152
- ret = umfPoolCreate ( umfDisjointPoolOps (), provider. get (),
153
- ( void *)config .get (), 0 , &pool1);
156
+ ret =
157
+ umfPoolCreate ( umfDisjointPoolOps (), provider .get (), params , 0 , &pool1);
154
158
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
155
159
auto poolHandle1 = umf_test::wrapPoolUnique (pool1);
156
160
157
- ret = umfPoolCreate ( umfDisjointPoolOps (), provider. get (),
158
- ( void *)config .get (), 0 , &pool2);
161
+ ret =
162
+ umfPoolCreate ( umfDisjointPoolOps (), provider .get (), params , 0 , &pool2);
159
163
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
160
164
auto poolHandle2 = umf_test::wrapPoolUnique (pool2);
161
165
166
+ ret = umfDisjointPoolParamsDestroy (params);
167
+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
168
+
162
169
EXPECT_EQ (0 , numAllocs);
163
170
EXPECT_EQ (0 , numFrees);
164
171
@@ -243,23 +250,24 @@ TEST_F(test, disjointPoolInvalidBucketSize) {
243
250
umfDisjointPoolParamsDestroy (params);
244
251
}
245
252
246
- disjoint_params_unique_handle_t defaultPoolConfig = poolConfig();
247
253
INSTANTIATE_TEST_SUITE_P (disjointPoolTests, umfPoolTest,
248
254
::testing::Values (poolCreateExtParams{
249
- umfDisjointPoolOps (),
250
- (void *)defaultPoolConfig.get (),
251
- &BA_GLOBAL_PROVIDER_OPS, nullptr }));
255
+ umfDisjointPoolOps (), defaultPoolConfig,
256
+ poolConfigDestroy, &BA_GLOBAL_PROVIDER_OPS,
257
+ nullptr , nullptr }));
258
+
259
+ void *memProviderParams () { return (void *)&DEFAULT_DISJOINT_CAPACITY; }
252
260
253
261
INSTANTIATE_TEST_SUITE_P (
254
262
disjointPoolTests, umfMemTest,
255
263
::testing::Values (std::make_tuple(
256
- poolCreateExtParams{
257
- umfDisjointPoolOps (), ( void *)defaultPoolConfig. get () ,
258
- &MOCK_OUT_OF_MEM_PROVIDER_OPS, ( void *)&DEFAULT_DISJOINT_CAPACITY },
264
+ poolCreateExtParams{umfDisjointPoolOps (), defaultPoolConfig,
265
+ poolConfigDestroy, &MOCK_OUT_OF_MEM_PROVIDER_OPS ,
266
+ memProviderParams, nullptr },
259
267
static_cast <int >(DEFAULT_DISJOINT_CAPACITY) / 2)));
260
268
261
269
INSTANTIATE_TEST_SUITE_P (disjointMultiPoolTests, umfMultiPoolTest,
262
270
::testing::Values (poolCreateExtParams{
263
- umfDisjointPoolOps (),
264
- ( void *)defaultPoolConfig. get () ,
265
- &BA_GLOBAL_PROVIDER_OPS , nullptr }));
271
+ umfDisjointPoolOps (), defaultPoolConfig,
272
+ poolConfigDestroy, &BA_GLOBAL_PROVIDER_OPS ,
273
+ nullptr , nullptr }));
0 commit comments