@@ -37,20 +37,29 @@ 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+ if (p) {
52+ auto handle =
53+ static_cast <umf_os_memory_provider_params_handle_t >(p);
54+ umfOsMemoryProviderParamsDestroy (handle);
55+ }
56+ };
57+
58+ return {static_cast <void *>(raw_params), deleter};
5059 }
5160
52- void * getParams () override { return params; }
53- umf_memory_provider_ops_t * getOps () override {
61+ umf_memory_provider_ops_t *
62+ getOps ([[maybe_unused]] ::benchmark::State &state ) override {
5463 return umfOsMemoryProviderOps ();
5564 }
5665 static std::string name () { return " os_provider" ; }
@@ -62,73 +71,66 @@ struct proxy_pool : public pool_interface<Provider> {
6271 getOps ([[maybe_unused]] ::benchmark::State &state) override {
6372 return umfProxyPoolOps ();
6473 }
65- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
66- return nullptr ;
67- }
74+
6875 static std::string name () { return " proxy_pool<" + Provider::name () + " >" ; }
6976};
7077
7178#ifdef UMF_POOL_DISJOINT_ENABLED
7279template <typename Provider>
7380struct disjoint_pool : public pool_interface <Provider> {
74- umf_disjoint_pool_params_handle_t disjoint_memory_pool_params;
81+ umf_memory_pool_ops_t *
82+ getOps ([[maybe_unused]] ::benchmark::State &state) override {
83+ return umfDisjointPoolOps ();
84+ }
7585
76- disjoint_pool () {
77- disjoint_memory_pool_params = NULL ;
78- auto ret = umfDisjointPoolParamsCreate (&disjoint_memory_pool_params);
86+ typename pool_interface<Provider>::params_ptr
87+ getParams (::benchmark::State &state) override {
88+ umf_disjoint_pool_params_handle_t raw_params = nullptr ;
89+ auto ret = umfDisjointPoolParamsCreate (&raw_params);
7990 if (ret != UMF_RESULT_SUCCESS) {
80- return ;
91+ state.SkipWithError (" Failed to create disjoint pool params" );
92+ return {nullptr , [](void *) {}};
8193 }
8294
83- // those function should never fail, so error handling is minimal.
84- ret = umfDisjointPoolParamsSetSlabMinSize (disjoint_memory_pool_params,
85- 4096 );
95+ ret = umfDisjointPoolParamsSetSlabMinSize (raw_params, 4096 );
8696 if (ret != UMF_RESULT_SUCCESS) {
87- goto err;
97+ state.SkipWithError (" Failed to set slab min size" );
98+ umfDisjointPoolParamsDestroy (raw_params);
99+ return {nullptr , [](void *) {}};
88100 }
89101
90- ret = umfDisjointPoolParamsSetCapacity (disjoint_memory_pool_params , 4 );
102+ ret = umfDisjointPoolParamsSetCapacity (raw_params , 4 );
91103 if (ret != UMF_RESULT_SUCCESS) {
92- goto err;
104+ state.SkipWithError (" Failed to set capacity" );
105+ umfDisjointPoolParamsDestroy (raw_params);
106+ return {nullptr , [](void *) {}};
93107 }
94108
95- ret = umfDisjointPoolParamsSetMinBucketSize (disjoint_memory_pool_params,
96- 4096 );
109+ ret = umfDisjointPoolParamsSetMinBucketSize (raw_params, 4096 );
97110 if (ret != UMF_RESULT_SUCCESS) {
98- goto err;
111+ state.SkipWithError (" Failed to set min bucket size" );
112+ umfDisjointPoolParamsDestroy (raw_params);
113+ return {nullptr , [](void *) {}};
99114 }
100115
101- ret = umfDisjointPoolParamsSetMaxPoolableSize (
102- disjoint_memory_pool_params, 4096 * 16 );
103-
116+ ret = umfDisjointPoolParamsSetMaxPoolableSize (raw_params, 4096 * 16 );
104117 if (ret != UMF_RESULT_SUCCESS) {
105- goto err;
118+ state.SkipWithError (" Failed to set max poolable size" );
119+ umfDisjointPoolParamsDestroy (raw_params);
120+ return {nullptr , [](void *) {}};
106121 }
107- return ;
108- err:
109-
110- umfDisjointPoolParamsDestroy (disjoint_memory_pool_params);
111- disjoint_memory_pool_params = NULL ;
112- }
113122
114- ~disjoint_pool () {
115- if (disjoint_memory_pool_params != NULL ) {
116- umfDisjointPoolParamsDestroy (disjoint_memory_pool_params);
117- }
118- }
123+ // Use a lambda as the deleter
124+ auto deleter = [](void *p) {
125+ if (p) {
126+ umfDisjointPoolParamsDestroy (
127+ static_cast <umf_disjoint_pool_params_handle_t >(p));
128+ }
129+ };
119130
120- umf_memory_pool_ops_t *
121- getOps ([[maybe_unused]] ::benchmark::State &state) override {
122- return umfDisjointPoolOps ();
131+ return {static_cast <void *>(raw_params), deleter};
123132 }
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- }
129133
130- return disjoint_memory_pool_params;
131- }
132134 static std::string name () {
133135 return " disjoint_pool<" + Provider::name () + " >" ;
134136 }
@@ -142,9 +144,7 @@ struct jemalloc_pool : public pool_interface<Provider> {
142144 getOps ([[maybe_unused]] ::benchmark::State &state) override {
143145 return umfJemallocPoolOps ();
144146 }
145- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
146- return NULL ;
147- }
147+
148148 static std::string name () {
149149 return " jemalloc_pool<" + Provider::name () + " >" ;
150150 }
@@ -158,10 +158,7 @@ struct scalable_pool : public pool_interface<Provider> {
158158 getOps ([[maybe_unused]] ::benchmark::State &state) override {
159159 return umfScalablePoolOps ();
160160 }
161- virtual void *
162- getParams ([[maybe_unused]] ::benchmark::State &state) override {
163- return NULL ;
164- }
161+
165162 static std::string name () {
166163 return " scalable_pool<" + Provider::name () + " >" ;
167164 }
0 commit comments