@@ -212,6 +212,13 @@ umfDefaultCtlPoolHandle(void *hPool, umf_ctl_query_source_t operationType,
212
212
return UMF_RESULT_ERROR_NOT_SUPPORTED ;
213
213
}
214
214
215
+ static umf_result_t umfDefaultTrimMemory (void * provider ,
216
+ size_t minBytesToKeep ) {
217
+ (void )provider ;
218
+ (void )minBytesToKeep ;
219
+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
220
+ }
221
+
215
222
// logical sum (OR) of all umf_pool_create_flags_t flags
216
223
static const umf_pool_create_flags_t UMF_POOL_CREATE_FLAG_ALL =
217
224
UMF_POOL_CREATE_FLAG_OWN_PROVIDER | UMF_POOL_CREATE_FLAG_DISABLE_TRACKING ;
@@ -233,9 +240,9 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
233
240
const void * params ,
234
241
umf_pool_create_flags_t flags ,
235
242
umf_memory_pool_handle_t * hPool ) {
236
- if (! ops || ! provider || ! hPool ) {
237
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
238
- }
243
+ UMF_CHECK (( ops != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
244
+ UMF_CHECK (( provider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT ) ;
245
+ UMF_CHECK (( hPool != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
239
246
240
247
// validate flags
241
248
if (flags & ~UMF_POOL_CREATE_FLAG_ALL ) {
@@ -245,10 +252,24 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
245
252
246
253
umf_result_t ret = UMF_RESULT_SUCCESS ;
247
254
255
+ umf_memory_pool_ops_t compatible_ops ;
248
256
if (ops -> version != UMF_POOL_OPS_VERSION_CURRENT ) {
249
257
LOG_WARN ("Memory Pool ops version \"%d\" is different than the current "
250
258
"version \"%d\"" ,
251
259
ops -> version , UMF_POOL_OPS_VERSION_CURRENT );
260
+
261
+ // Create a new ops compatible structure with the current version
262
+ memset (& compatible_ops , 0 , sizeof (compatible_ops ));
263
+ if (UMF_MINOR_VERSION (ops -> version ) == 0 ) {
264
+ LOG_INFO ("Detected 1.0 version of Memory Pool ops, "
265
+ "upgrading to current version" );
266
+ memcpy (& compatible_ops , ops ,
267
+ offsetof(umf_memory_pool_ops_t , ext_trim_memory ));
268
+ } else {
269
+ LOG_ERR ("Unsupported Memory Pool ops version: %d" , ops -> version );
270
+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
271
+ }
272
+ ops = & compatible_ops ;
252
273
}
253
274
254
275
umf_memory_pool_handle_t pool =
@@ -278,6 +299,10 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
278
299
pool -> ops .ext_ctl = umfDefaultCtlPoolHandle ;
279
300
}
280
301
302
+ if (NULL == pool -> ops .ext_trim_memory ) {
303
+ pool -> ops .ext_trim_memory = umfDefaultTrimMemory ;
304
+ }
305
+
281
306
if (NULL == utils_mutex_init (& pool -> lock )) {
282
307
LOG_ERR ("Failed to initialize mutex for pool" );
283
308
ret = UMF_RESULT_ERROR_UNKNOWN ;
@@ -326,10 +351,7 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
326
351
}
327
352
328
353
umf_result_t umfPoolDestroy (umf_memory_pool_handle_t hPool ) {
329
- if (hPool == NULL ) {
330
- LOG_ERR ("memory pool handle is NULL" );
331
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
332
- }
354
+ UMF_CHECK ((hPool != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
333
355
334
356
if (umf_ba_global_is_destroyed ()) {
335
357
return UMF_RESULT_ERROR_UNKNOWN ;
@@ -509,6 +531,13 @@ umf_result_t umfPoolGetTag(umf_memory_pool_handle_t hPool, void **tag) {
509
531
return UMF_RESULT_SUCCESS ;
510
532
}
511
533
534
+ umf_result_t umfPoolTrimMemory (umf_memory_pool_handle_t hPool ,
535
+ size_t minBytesToKeep ) {
536
+ UMF_CHECK ((hPool != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
537
+
538
+ return hPool -> ops .ext_trim_memory (hPool -> pool_priv , minBytesToKeep );
539
+ }
540
+
512
541
void umfPoolCtlDefaultsDestroy (void ) {
513
542
utils_init_once (& mem_pool_ctl_initialized , pool_ctl_init );
514
543
0 commit comments