@@ -37,20 +37,27 @@ struct glibc_malloc : public allocator_interface {
3737};
3838
3939struct os_provider : public provider_interface {
40- umf_os_memory_provider_params_handle_t params = NULL ;
41- os_provider () {
42- umfOsMemoryProviderParamsCreate (¶ms);
43- return ;
44- }
45-
46- ~os_provider () {
47- if (params != NULL ) {
48- umfOsMemoryProviderParamsDestroy (params);
40+ provider_interface::params_ptr
41+ getParams (::benchmark::State &state) override {
42+ umf_os_memory_provider_params_handle_t raw_params = nullptr ;
43+ umfOsMemoryProviderParamsCreate (&raw_params);
44+ if (!raw_params) {
45+ state.SkipWithError (" Failed to create os provider params" );
46+ return {nullptr , [](void *) {}};
4947 }
48+
49+ // Use a lambda as the custom deleter
50+ auto deleter = [](void *p) {
51+ auto handle =
52+ static_cast <umf_os_memory_provider_params_handle_t >(p);
53+ umfOsMemoryProviderParamsDestroy (handle);
54+ };
55+
56+ return {static_cast <void *>(raw_params), deleter};
5057 }
5158
52- void * getParams () override { return params; }
53- umf_memory_provider_ops_t * getOps () override {
59+ umf_memory_provider_ops_t *
60+ getOps ([[maybe_unused]] ::benchmark::State &state ) override {
5461 return umfOsMemoryProviderOps ();
5562 }
5663 static std::string name () { return " os_provider" ; }
@@ -62,73 +69,63 @@ struct proxy_pool : public pool_interface<Provider> {
6269 getOps ([[maybe_unused]] ::benchmark::State &state) override {
6370 return umfProxyPoolOps ();
6471 }
65- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
66- return nullptr ;
67- }
72+
6873 static std::string name () { return " proxy_pool<" + Provider::name () + " >" ; }
6974};
7075
7176#ifdef UMF_POOL_DISJOINT_ENABLED
7277template <typename Provider>
7378struct disjoint_pool : public pool_interface <Provider> {
74- umf_disjoint_pool_params_handle_t disjoint_memory_pool_params;
79+ umf_memory_pool_ops_t *
80+ getOps ([[maybe_unused]] ::benchmark::State &state) override {
81+ return umfDisjointPoolOps ();
82+ }
7583
76- disjoint_pool () {
77- disjoint_memory_pool_params = NULL ;
78- auto ret = umfDisjointPoolParamsCreate (&disjoint_memory_pool_params);
84+ typename pool_interface<Provider>::params_ptr
85+ getParams (::benchmark::State &state) override {
86+ umf_disjoint_pool_params_handle_t raw_params = nullptr ;
87+ auto ret = umfDisjointPoolParamsCreate (&raw_params);
7988 if (ret != UMF_RESULT_SUCCESS) {
80- return ;
89+ state.SkipWithError (" Failed to create disjoint pool params" );
90+ return {nullptr , [](void *) {}};
8191 }
8292
83- // those function should never fail, so error handling is minimal.
84- ret = umfDisjointPoolParamsSetSlabMinSize (disjoint_memory_pool_params,
85- 4096 );
93+ ret = umfDisjointPoolParamsSetSlabMinSize (raw_params, 4096 );
8694 if (ret != UMF_RESULT_SUCCESS) {
87- goto err;
95+ state.SkipWithError (" Failed to set slab min size" );
96+ umfDisjointPoolParamsDestroy (raw_params);
97+ return {nullptr , [](void *) {}};
8898 }
8999
90- ret = umfDisjointPoolParamsSetCapacity (disjoint_memory_pool_params , 4 );
100+ ret = umfDisjointPoolParamsSetCapacity (raw_params , 4 );
91101 if (ret != UMF_RESULT_SUCCESS) {
92- goto err;
102+ state.SkipWithError (" Failed to set capacity" );
103+ umfDisjointPoolParamsDestroy (raw_params);
104+ return {nullptr , [](void *) {}};
93105 }
94106
95- ret = umfDisjointPoolParamsSetMinBucketSize (disjoint_memory_pool_params,
96- 4096 );
107+ ret = umfDisjointPoolParamsSetMinBucketSize (raw_params, 4096 );
97108 if (ret != UMF_RESULT_SUCCESS) {
98- goto err;
109+ state.SkipWithError (" Failed to set min bucket size" );
110+ umfDisjointPoolParamsDestroy (raw_params);
111+ return {nullptr , [](void *) {}};
99112 }
100113
101- ret = umfDisjointPoolParamsSetMaxPoolableSize (
102- disjoint_memory_pool_params, 4096 * 16 );
103-
114+ ret = umfDisjointPoolParamsSetMaxPoolableSize (raw_params, 4096 * 16 );
104115 if (ret != UMF_RESULT_SUCCESS) {
105- goto err;
116+ state.SkipWithError (" Failed to set max poolable size" );
117+ umfDisjointPoolParamsDestroy (raw_params);
118+ return {nullptr , [](void *) {}};
106119 }
107- return ;
108- err:
109-
110- umfDisjointPoolParamsDestroy (disjoint_memory_pool_params);
111- disjoint_memory_pool_params = NULL ;
112- }
113120
114- ~disjoint_pool () {
115- if (disjoint_memory_pool_params != NULL ) {
116- umfDisjointPoolParamsDestroy (disjoint_memory_pool_params);
117- }
118- }
121+ auto deleter = [](void *p) {
122+ umfDisjointPoolParamsDestroy (
123+ static_cast <umf_disjoint_pool_params_handle_t >(p));
124+ };
119125
120- umf_memory_pool_ops_t *
121- getOps ([[maybe_unused]] ::benchmark::State &state) override {
122- return umfDisjointPoolOps ();
126+ return {static_cast <void *>(raw_params), deleter};
123127 }
124- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
125-
126- if (disjoint_memory_pool_params == NULL ) {
127- state.SkipWithError (" Failed to create disjoint pool params" );
128- }
129128
130- return disjoint_memory_pool_params;
131- }
132129 static std::string name () {
133130 return " disjoint_pool<" + Provider::name () + " >" ;
134131 }
@@ -142,9 +139,7 @@ struct jemalloc_pool : public pool_interface<Provider> {
142139 getOps ([[maybe_unused]] ::benchmark::State &state) override {
143140 return umfJemallocPoolOps ();
144141 }
145- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
146- return NULL ;
147- }
142+
148143 static std::string name () {
149144 return " jemalloc_pool<" + Provider::name () + " >" ;
150145 }
@@ -158,10 +153,7 @@ struct scalable_pool : public pool_interface<Provider> {
158153 getOps ([[maybe_unused]] ::benchmark::State &state) override {
159154 return umfScalablePoolOps ();
160155 }
161- virtual void *
162- getParams ([[maybe_unused]] ::benchmark::State &state) override {
163- return NULL ;
164- }
156+
165157 static std::string name () {
166158 return " scalable_pool<" + Provider::name () + " >" ;
167159 }
0 commit comments