@@ -110,9 +110,9 @@ int consumer_connect(int port) {
110
110
return ret ;
111
111
}
112
112
113
- int run_consumer (int port , umf_memory_provider_ops_t * provider_ops ,
114
- void * provider_params , memcopy_callback_t memcopy_callback ,
115
- void * memcopy_ctx ) {
113
+ int run_consumer (int port , umf_memory_pool_ops_t * pool_ops , void * pool_params ,
114
+ umf_memory_provider_ops_t * provider_ops , void * provider_params ,
115
+ memcopy_callback_t memcopy_callback , void * memcopy_ctx ) {
116
116
char consumer_message [MSG_SIZE ];
117
117
int producer_socket = -1 ;
118
118
int ret = -1 ;
@@ -131,6 +131,9 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
131
131
return -1 ;
132
132
}
133
133
134
+ umf_memory_pool_handle_t pool ;
135
+ umf_result = umfPoolCreate (pool_ops , provider , pool_params , 0 , & pool );
136
+
134
137
producer_socket = consumer_connect (port );
135
138
if (producer_socket < 0 ) {
136
139
goto err_umfMemoryProviderDestroy ;
@@ -183,7 +186,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
183
186
len );
184
187
185
188
void * SHM_ptr ;
186
- umf_result = umfMemoryProviderOpenIPCHandle ( provider , IPC_handle , & SHM_ptr );
189
+ umf_result = umfOpenIPCHandle ( pool , IPC_handle , & SHM_ptr );
187
190
if (umf_result == UMF_RESULT_ERROR_NOT_SUPPORTED ) {
188
191
fprintf (stderr ,
189
192
"[consumer] SKIP: opening the IPC handle is not supported\n" );
@@ -240,8 +243,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
240
243
241
244
err_closeIPCHandle :
242
245
// we do not know the exact size of the remote shared memory
243
- umf_result = umfMemoryProviderCloseIPCHandle (provider , SHM_ptr ,
244
- sizeof (unsigned long long ));
246
+ umf_result = umfCloseIPCHandle (SHM_ptr );
245
247
if (umf_result != UMF_RESULT_SUCCESS ) {
246
248
fprintf (stderr , "[consumer] ERROR: closing the IPC handle failed\n" );
247
249
}
@@ -254,6 +256,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
254
256
255
257
err_umfMemoryProviderDestroy :
256
258
umfMemoryProviderDestroy (provider );
259
+ umfPoolDestroy (pool );
257
260
258
261
if (ret == 0 ) {
259
262
fprintf (stderr , "[consumer] Shutting down (status OK) ...\n" );
@@ -303,9 +306,9 @@ int producer_connect(int port) {
303
306
return -1 ;
304
307
}
305
308
306
- int run_producer (int port , umf_memory_provider_ops_t * provider_ops ,
307
- void * provider_params , memcopy_callback_t memcopy_callback ,
308
- void * memcopy_ctx ) {
309
+ int run_producer (int port , umf_memory_pool_ops_t * pool_ops , void * pool_params ,
310
+ umf_memory_provider_ops_t * provider_ops , void * provider_params ,
311
+ memcopy_callback_t memcopy_callback , void * memcopy_ctx ) {
309
312
int ret = -1 ;
310
313
umf_memory_provider_handle_t provider = NULL ;
311
314
umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN ;
@@ -321,6 +324,9 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
321
324
return -1 ;
322
325
}
323
326
327
+ umf_memory_pool_handle_t pool ;
328
+ umf_result = umfPoolCreate (pool_ops , provider , pool_params , 0 , & pool );
329
+
324
330
size_t page_size ;
325
331
umf_result = umfMemoryProviderGetMinPageSize (provider , NULL , & page_size );
326
332
if (umf_result != UMF_RESULT_SUCCESS ) {
@@ -335,45 +341,36 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
335
341
size_t ptr2_size = 2 * page_size ;
336
342
size_t size_IPC_shared_memory = 3 * page_size ;
337
343
338
- umf_result = umfMemoryProviderAlloc ( provider , ptr1_size , 0 , & ptr1 );
339
- if (umf_result != UMF_RESULT_SUCCESS ) {
344
+ ptr1 = umfPoolMalloc ( pool , ptr1_size );
345
+ if (ptr1 == NULL ) {
340
346
fprintf (stderr , "[producer] ERROR: allocating 1 page failed\n" );
341
347
goto err_umfMemoryProviderDestroy ;
342
348
}
343
349
344
- umf_result = umfMemoryProviderAlloc ( provider , ptr2_size , 0 , & ptr2 );
345
- if (umf_result != UMF_RESULT_SUCCESS ) {
350
+ ptr2 = umfPoolMalloc ( pool , ptr2_size );
351
+ if (ptr2 == NULL ) {
346
352
fprintf (stderr , "[producer] ERROR: allocating 2 pages failed\n" );
347
353
goto err_free_ptr1 ;
348
354
}
349
355
350
- umf_result = umfMemoryProviderAlloc (provider , size_IPC_shared_memory , 0 ,
351
- & IPC_shared_memory );
352
- if (umf_result != UMF_RESULT_SUCCESS ) {
356
+ IPC_shared_memory = umfPoolMalloc (pool , size_IPC_shared_memory );
357
+ if (IPC_shared_memory == NULL ) {
353
358
fprintf (stderr , "[producer] ERROR: allocating 3 pages failed\n" );
354
359
goto err_free_ptr2 ;
355
360
}
356
361
357
362
// get size of the IPC handle
358
363
size_t IPC_handle_size ;
359
- umf_result = umfMemoryProviderGetIPCHandleSize (provider , & IPC_handle_size );
360
- if (umf_result != UMF_RESULT_SUCCESS ) {
361
- fprintf (stderr ,
362
- "[producer] ERROR: getting size of the IPC handle failed\n" );
363
- goto err_free_IPC_shared_memory ;
364
- }
364
+ umf_ipc_handle_t IPC_handle = NULL ;
365
365
366
- // allocate data for IPC provider
367
- void * IPC_handle = malloc ( IPC_handle_size );
368
- if ( IPC_handle == NULL ) {
369
- fprintf ( stderr ,
370
- "[producer] ERROR: allocating memory for IPC handle failed\n" );
366
+ // get the IPC handle
367
+ umf_result =
368
+ umfGetIPCHandle ( IPC_shared_memory , & IPC_handle , & IPC_handle_size );
369
+ if ( umf_result != UMF_RESULT_SUCCESS ) {
370
+ fprintf ( stderr , "[producer] ERROR: getting the IPC handle failed\n" );
371
371
goto err_free_IPC_shared_memory ;
372
372
}
373
373
374
- // zero the IPC handle and the shared memory
375
- memset (IPC_handle , 0 , IPC_handle_size );
376
-
377
374
// save a random number (&provider) in the shared memory
378
375
unsigned long long SHM_number_1 = (unsigned long long )& provider ;
379
376
memcopy_callback (IPC_shared_memory , & SHM_number_1 , sizeof (SHM_number_1 ),
@@ -382,16 +379,6 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
382
379
fprintf (stderr , "[producer] My shared memory contains a number: %llu\n" ,
383
380
SHM_number_1 );
384
381
385
- // get the IPC handle from the OS memory provider
386
- umf_result = umfMemoryProviderGetIPCHandle (
387
- provider , IPC_shared_memory , size_IPC_shared_memory , IPC_handle );
388
- if (umf_result != UMF_RESULT_SUCCESS ) {
389
- fprintf (stderr ,
390
- "[producer] ERROR: getting the IPC handle from the OS memory "
391
- "provider failed\n" );
392
- goto err_free_IPC_handle ;
393
- }
394
-
395
382
fprintf (stderr , "[producer] Got the IPC handle\n" );
396
383
397
384
producer_socket = producer_connect (port );
@@ -494,23 +481,24 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
494
481
close (producer_socket );
495
482
496
483
err_PutIPCHandle :
497
- umf_result = umfMemoryProviderPutIPCHandle ( provider , IPC_handle );
484
+ umf_result = umfPutIPCHandle ( IPC_handle );
498
485
if (umf_result != UMF_RESULT_SUCCESS ) {
499
486
fprintf (stderr , "[producer] ERROR: putting the IPC handle failed\n" );
500
487
}
501
488
502
489
fprintf (stderr , "[producer] Put the IPC handle\n" );
503
490
504
- err_free_IPC_handle :
505
- free (IPC_handle );
506
491
err_free_IPC_shared_memory :
507
- (void )umfMemoryProviderFree ( provider , IPC_shared_memory ,
508
- size_IPC_shared_memory );
492
+ (void )umfFree ( IPC_shared_memory );
493
+
509
494
err_free_ptr2 :
510
- (void )umfMemoryProviderFree (provider , ptr2 , ptr2_size );
495
+ (void )umfFree (ptr2 );
496
+
511
497
err_free_ptr1 :
512
- (void )umfMemoryProviderFree (provider , ptr1 , ptr1_size );
498
+ (void )umfFree (ptr1 );
499
+
513
500
err_umfMemoryProviderDestroy :
501
+ umfPoolDestroy (pool );
514
502
umfMemoryProviderDestroy (provider );
515
503
516
504
if (ret == 0 ) {
0 commit comments