@@ -37,20 +37,30 @@ 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 provider_interface::params_ptr (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 provider_interface::params_ptr (static_cast <void *>(raw_params),
59+ deleter);
5060 }
5161
52- void * getParams () override { return params; }
53- umf_memory_provider_ops_t * getOps () override {
62+ umf_memory_provider_ops_t *
63+ getOps ([[maybe_unused]] ::benchmark::State &state ) override {
5464 return umfOsMemoryProviderOps ();
5565 }
5666 static std::string name () { return " os_provider" ; }
@@ -62,73 +72,66 @@ struct proxy_pool : public pool_interface<Provider> {
6272 getOps ([[maybe_unused]] ::benchmark::State &state) override {
6373 return umfProxyPoolOps ();
6474 }
65- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
66- return nullptr ;
67- }
75+
6876 static std::string name () { return " proxy_pool<" + Provider::name () + " >" ; }
6977};
7078
7179#ifdef UMF_POOL_DISJOINT_ENABLED
7280template <typename Provider>
7381struct disjoint_pool : public pool_interface <Provider> {
74- umf_disjoint_pool_params_handle_t disjoint_memory_pool_params;
82+ umf_memory_pool_ops_t *
83+ getOps ([[maybe_unused]] ::benchmark::State &state) override {
84+ return umfDisjointPoolOps ();
85+ }
7586
76- disjoint_pool () {
77- disjoint_memory_pool_params = NULL ;
78- auto ret = umfDisjointPoolParamsCreate (&disjoint_memory_pool_params);
87+ typename pool_interface<Provider>::params_ptr
88+ getParams (::benchmark::State &state) override {
89+ umf_disjoint_pool_params_handle_t raw_params = nullptr ;
90+ auto ret = umfDisjointPoolParamsCreate (&raw_params);
7991 if (ret != UMF_RESULT_SUCCESS) {
80- return ;
92+ state.SkipWithError (" Failed to create disjoint pool params" );
93+ return {nullptr , [](void *) {}};
8194 }
8295
83- // those function should never fail, so error handling is minimal.
84- ret = umfDisjointPoolParamsSetSlabMinSize (disjoint_memory_pool_params,
85- 4096 );
96+ ret = umfDisjointPoolParamsSetSlabMinSize (raw_params, 4096 );
8697 if (ret != UMF_RESULT_SUCCESS) {
87- goto err;
98+ state.SkipWithError (" Failed to set slab min size" );
99+ umfDisjointPoolParamsDestroy (raw_params);
100+ return {nullptr , [](void *) {}};
88101 }
89102
90- ret = umfDisjointPoolParamsSetCapacity (disjoint_memory_pool_params , 4 );
103+ ret = umfDisjointPoolParamsSetCapacity (raw_params , 4 );
91104 if (ret != UMF_RESULT_SUCCESS) {
92- goto err;
105+ state.SkipWithError (" Failed to set capacity" );
106+ umfDisjointPoolParamsDestroy (raw_params);
107+ return {nullptr , [](void *) {}};
93108 }
94109
95- ret = umfDisjointPoolParamsSetMinBucketSize (disjoint_memory_pool_params,
96- 4096 );
110+ ret = umfDisjointPoolParamsSetMinBucketSize (raw_params, 4096 );
97111 if (ret != UMF_RESULT_SUCCESS) {
98- goto err;
112+ state.SkipWithError (" Failed to set min bucket size" );
113+ umfDisjointPoolParamsDestroy (raw_params);
114+ return {nullptr , [](void *) {}};
99115 }
100116
101- ret = umfDisjointPoolParamsSetMaxPoolableSize (
102- disjoint_memory_pool_params, 4096 * 16 );
103-
117+ ret = umfDisjointPoolParamsSetMaxPoolableSize (raw_params, 4096 * 16 );
104118 if (ret != UMF_RESULT_SUCCESS) {
105- goto err;
119+ state.SkipWithError (" Failed to set max poolable size" );
120+ umfDisjointPoolParamsDestroy (raw_params);
121+ return {nullptr , [](void *) {}};
106122 }
107- return ;
108- err:
109123
110- umfDisjointPoolParamsDestroy (disjoint_memory_pool_params);
111- disjoint_memory_pool_params = NULL ;
112- }
124+ // Use a lambda as the deleter
125+ auto deleter = [](void *p) {
126+ if (p) {
127+ umfDisjointPoolParamsDestroy (
128+ static_cast <umf_disjoint_pool_params_handle_t >(p));
129+ }
130+ };
113131
114- ~disjoint_pool () {
115- if (disjoint_memory_pool_params != NULL ) {
116- umfDisjointPoolParamsDestroy (disjoint_memory_pool_params);
117- }
132+ return {static_cast <void *>(raw_params), deleter};
118133 }
119134
120- umf_memory_pool_ops_t *
121- getOps ([[maybe_unused]] ::benchmark::State &state) override {
122- return umfDisjointPoolOps ();
123- }
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- }
129-
130- return disjoint_memory_pool_params;
131- }
132135 static std::string name () {
133136 return " disjoint_pool<" + Provider::name () + " >" ;
134137 }
@@ -142,9 +145,7 @@ struct jemalloc_pool : public pool_interface<Provider> {
142145 getOps ([[maybe_unused]] ::benchmark::State &state) override {
143146 return umfJemallocPoolOps ();
144147 }
145- void *getParams ([[maybe_unused]] ::benchmark::State &state) override {
146- return NULL ;
147- }
148+
148149 static std::string name () {
149150 return " jemalloc_pool<" + Provider::name () + " >" ;
150151 }
@@ -158,10 +159,7 @@ struct scalable_pool : public pool_interface<Provider> {
158159 getOps ([[maybe_unused]] ::benchmark::State &state) override {
159160 return umfScalablePoolOps ();
160161 }
161- virtual void *
162- getParams ([[maybe_unused]] ::benchmark::State &state) override {
163- return NULL ;
164- }
162+
165163 static std::string name () {
166164 return " scalable_pool<" + Provider::name () + " >" ;
167165 }
0 commit comments