@@ -167,6 +167,15 @@ umfDefaultCtlPoolHandle(void *hPool, umf_ctl_query_source_t operationType,
167167 return UMF_RESULT_ERROR_NOT_SUPPORTED ;
168168}
169169
170+ static umf_result_t
171+ umfDefaultExtPostInitialize (umf_memory_provider_handle_t provider ,
172+ const void * params , void * pool ) {
173+ (void )provider ;
174+ (void )params ;
175+ (void )pool ;
176+ return UMF_RESULT_SUCCESS ;
177+ }
178+
170179// logical sum (OR) of all umf_pool_create_flags_t flags
171180static const umf_pool_create_flags_t UMF_POOL_CREATE_FLAG_ALL =
172181 UMF_POOL_CREATE_FLAG_OWN_PROVIDER | UMF_POOL_CREATE_FLAG_DISABLE_TRACKING ;
@@ -200,11 +209,26 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
200209 }
201210
202211 umf_result_t ret = UMF_RESULT_SUCCESS ;
203-
212+ umf_memory_pool_ops_t compatible_ops ;
204213 if (ops -> version != UMF_POOL_OPS_VERSION_CURRENT ) {
205214 LOG_WARN ("Memory Pool ops version \"%d\" is different than the current "
206215 "version \"%d\"" ,
207216 ops -> version , UMF_POOL_OPS_VERSION_CURRENT );
217+
218+ // Create a new ops compatible structure with the current version
219+ memset (& compatible_ops , 0 , sizeof (compatible_ops ));
220+ if (UMF_MINOR_VERSION (ops -> version ) == 0 ) {
221+ LOG_INFO ("Detected 1.0 version of Memory Pool ops, "
222+ "upgrading to current version" );
223+ memcpy (& compatible_ops , ops ,
224+ offsetof(umf_memory_pool_ops_t , ext_post_initialize ));
225+ } else {
226+ LOG_ERR ("Memory Pool ops unknown version, which \"%d\" is not "
227+ "supported" ,
228+ ops -> version );
229+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
230+ }
231+ ops = & compatible_ops ;
208232 }
209233
210234 umf_memory_pool_handle_t pool =
@@ -234,13 +258,17 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
234258 pool -> ops .ext_ctl = umfDefaultCtlPoolHandle ;
235259 }
236260
261+ if (NULL == pool -> ops .ext_post_initialize ) {
262+ pool -> ops .ext_post_initialize = umfDefaultExtPostInitialize ;
263+ }
264+
237265 if (NULL == utils_mutex_init (& pool -> lock )) {
238266 LOG_ERR ("Failed to initialize mutex for pool" );
239267 ret = UMF_RESULT_ERROR_UNKNOWN ;
240268 goto err_lock_init ;
241269 }
242270
243- ret = ops -> initialize (pool -> provider , params , & pool -> pool_priv );
271+ ret = pool -> ops . initialize (pool -> provider , params , & pool -> pool_priv );
244272 if (ret != UMF_RESULT_SUCCESS ) {
245273 goto err_pool_init ;
246274 }
@@ -261,7 +289,15 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
261289 }
262290 }
263291
292+ ret =
293+ pool -> ops .ext_post_initialize (pool -> provider , params , pool -> pool_priv );
294+ if (ret != UMF_RESULT_SUCCESS ) {
295+ LOG_ERR ("Failed to post-initialize pool" );
296+ goto err_pool_init ;
297+ }
298+
264299 * hPool = pool ;
300+
265301 LOG_INFO ("Memory pool created: %p" , (void * )pool );
266302 return UMF_RESULT_SUCCESS ;
267303
0 commit comments