@@ -167,6 +167,14 @@ umfDefaultCtlPoolHandle(void *hPool, umf_ctl_query_source_t operationType,
167167 return UMF_RESULT_ERROR_NOT_SUPPORTED ;
168168}
169169
170+ static umf_result_t umfDefaultExtPostInitialize (umf_memory_provider_handle_t provider ,
171+ const void * params , void * pool ) {
172+ (void )provider ;
173+ (void )params ;
174+ (void )pool ;
175+ return UMF_RESULT_SUCCESS ;
176+ }
177+
170178// logical sum (OR) of all umf_pool_create_flags_t flags
171179static const umf_pool_create_flags_t UMF_POOL_CREATE_FLAG_ALL =
172180 UMF_POOL_CREATE_FLAG_OWN_PROVIDER | UMF_POOL_CREATE_FLAG_DISABLE_TRACKING ;
@@ -200,11 +208,26 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
200208 }
201209
202210 umf_result_t ret = UMF_RESULT_SUCCESS ;
203-
211+ umf_memory_pool_ops_t compatible_ops ;
204212 if (ops -> version != UMF_POOL_OPS_VERSION_CURRENT ) {
205213 LOG_WARN ("Memory Pool ops version \"%d\" is different than the current "
206214 "version \"%d\"" ,
207215 ops -> version , UMF_POOL_OPS_VERSION_CURRENT );
216+
217+ // Create a new ops compatible structure with the current version
218+ memset (& compatible_ops , 0 , sizeof (compatible_ops ));
219+ if (UMF_MINOR_VERSION (ops -> version ) == 0 ) {
220+ LOG_INFO ("Detected 1.0 version of Memory Pool ops, "
221+ "upgrading to current version" );
222+ memcpy (& compatible_ops , ops ,
223+ offsetof(umf_memory_pool_ops_t , ext_post_initialize ));
224+ } else {
225+ LOG_ERR ("Memory Pool ops unknown version, which \"%d\" is not "
226+ "supported" ,
227+ ops -> version );
228+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
229+ }
230+ ops = & compatible_ops ;
208231 }
209232
210233 umf_memory_pool_handle_t pool =
@@ -234,13 +257,17 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
234257 pool -> ops .ext_ctl = umfDefaultCtlPoolHandle ;
235258 }
236259
260+ if (NULL == pool -> ops .ext_post_initialize ) {
261+ pool -> ops .ext_post_initialize = umfDefaultExtPostInitialize ;
262+ }
263+
237264 if (NULL == utils_mutex_init (& pool -> lock )) {
238265 LOG_ERR ("Failed to initialize mutex for pool" );
239266 ret = UMF_RESULT_ERROR_UNKNOWN ;
240267 goto err_lock_init ;
241268 }
242269
243- ret = ops -> initialize (pool -> provider , params , & pool -> pool_priv );
270+ ret = pool -> ops . initialize (pool -> provider , params , & pool -> pool_priv );
244271 if (ret != UMF_RESULT_SUCCESS ) {
245272 goto err_pool_init ;
246273 }
@@ -261,7 +288,14 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
261288 }
262289 }
263290
291+ ret = pool -> ops .ext_post_initialize (pool -> provider , params , pool -> pool_priv );
292+ if (ret != UMF_RESULT_SUCCESS ) {
293+ LOG_ERR ("Failed to post-initialize pool" );
294+ goto err_pool_init ;
295+ }
296+
264297 * hPool = pool ;
298+
265299 LOG_INFO ("Memory pool created: %p" , (void * )pool );
266300 return UMF_RESULT_SUCCESS ;
267301
0 commit comments