@@ -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,16 +131,23 @@ 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
+ if (umf_result != UMF_RESULT_SUCCESS ) {
137
+ fprintf (stderr , "[consumer] ERROR: creating memory pool failed\n" );
138
+ goto err_umfMemoryProviderDestroy ;
139
+ }
140
+
134
141
producer_socket = consumer_connect (port );
135
142
if (producer_socket < 0 ) {
136
- goto err_umfMemoryProviderDestroy ;
143
+ goto err_umfMemoryPoolDestroy ;
137
144
}
138
145
139
146
// allocate the zeroed receive buffer
140
147
char * recv_buffer = calloc (1 , MSG_SIZE );
141
148
if (!recv_buffer ) {
142
149
fprintf (stderr , "[consumer] ERROR: out of memory\n" );
143
- goto err_umfMemoryProviderDestroy ;
150
+ goto err_umfMemoryPoolDestroy ;
144
151
}
145
152
146
153
// get the size of the IPC handle from the producer
@@ -183,7 +190,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
183
190
len );
184
191
185
192
void * SHM_ptr ;
186
- umf_result = umfMemoryProviderOpenIPCHandle ( provider , IPC_handle , & SHM_ptr );
193
+ umf_result = umfOpenIPCHandle ( pool , IPC_handle , & SHM_ptr );
187
194
if (umf_result == UMF_RESULT_ERROR_NOT_SUPPORTED ) {
188
195
fprintf (stderr ,
189
196
"[consumer] SKIP: opening the IPC handle is not supported\n" );
@@ -240,8 +247,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
240
247
241
248
err_closeIPCHandle :
242
249
// we do not know the exact size of the remote shared memory
243
- umf_result = umfMemoryProviderCloseIPCHandle (provider , SHM_ptr ,
244
- sizeof (unsigned long long ));
250
+ umf_result = umfCloseIPCHandle (SHM_ptr );
245
251
if (umf_result != UMF_RESULT_SUCCESS ) {
246
252
fprintf (stderr , "[consumer] ERROR: closing the IPC handle failed\n" );
247
253
}
@@ -252,6 +258,9 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
252
258
err_close_producer_socket :
253
259
close (producer_socket );
254
260
261
+ err_umfMemoryPoolDestroy :
262
+ umfPoolDestroy (pool );
263
+
255
264
err_umfMemoryProviderDestroy :
256
265
umfMemoryProviderDestroy (provider );
257
266
@@ -303,9 +312,9 @@ int producer_connect(int port) {
303
312
return -1 ;
304
313
}
305
314
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 ) {
315
+ int run_producer (int port , umf_memory_pool_ops_t * pool_ops , void * pool_params ,
316
+ umf_memory_provider_ops_t * provider_ops , void * provider_params ,
317
+ memcopy_callback_t memcopy_callback , void * memcopy_ctx ) {
309
318
int ret = -1 ;
310
319
umf_memory_provider_handle_t provider = NULL ;
311
320
umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN ;
@@ -321,12 +330,19 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
321
330
return -1 ;
322
331
}
323
332
333
+ umf_memory_pool_handle_t pool ;
334
+ umf_result = umfPoolCreate (pool_ops , provider , pool_params , 0 , & pool );
335
+ if (umf_result != UMF_RESULT_SUCCESS ) {
336
+ fprintf (stderr , "[producer] ERROR: creating memory pool failed\n" );
337
+ goto err_umfMemoryProviderDestroy ;
338
+ }
339
+
324
340
size_t page_size ;
325
341
umf_result = umfMemoryProviderGetMinPageSize (provider , NULL , & page_size );
326
342
if (umf_result != UMF_RESULT_SUCCESS ) {
327
343
fprintf (stderr ,
328
344
"[producer] ERROR: getting the minimum page size failed\n" );
329
- goto err_umfMemoryProviderDestroy ;
345
+ goto err_umfMemoryPoolDestroy ;
330
346
}
331
347
332
348
// Make 3 allocations of size: 1 page, 2 pages and 3 pages
@@ -335,45 +351,36 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
335
351
size_t ptr2_size = 2 * page_size ;
336
352
size_t size_IPC_shared_memory = 3 * page_size ;
337
353
338
- umf_result = umfMemoryProviderAlloc ( provider , ptr1_size , 0 , & ptr1 );
339
- if (umf_result != UMF_RESULT_SUCCESS ) {
354
+ ptr1 = umfPoolMalloc ( pool , ptr1_size );
355
+ if (ptr1 == NULL ) {
340
356
fprintf (stderr , "[producer] ERROR: allocating 1 page failed\n" );
341
- goto err_umfMemoryProviderDestroy ;
357
+ goto err_umfMemoryPoolDestroy ;
342
358
}
343
359
344
- umf_result = umfMemoryProviderAlloc ( provider , ptr2_size , 0 , & ptr2 );
345
- if (umf_result != UMF_RESULT_SUCCESS ) {
360
+ ptr2 = umfPoolMalloc ( pool , ptr2_size );
361
+ if (ptr2 == NULL ) {
346
362
fprintf (stderr , "[producer] ERROR: allocating 2 pages failed\n" );
347
363
goto err_free_ptr1 ;
348
364
}
349
365
350
- umf_result = umfMemoryProviderAlloc (provider , size_IPC_shared_memory , 0 ,
351
- & IPC_shared_memory );
352
- if (umf_result != UMF_RESULT_SUCCESS ) {
366
+ IPC_shared_memory = umfPoolMalloc (pool , size_IPC_shared_memory );
367
+ if (IPC_shared_memory == NULL ) {
353
368
fprintf (stderr , "[producer] ERROR: allocating 3 pages failed\n" );
354
369
goto err_free_ptr2 ;
355
370
}
356
371
357
372
// get size of the IPC handle
358
373
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
- }
374
+ umf_ipc_handle_t IPC_handle = NULL ;
365
375
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" );
376
+ // get the IPC handle
377
+ umf_result =
378
+ umfGetIPCHandle ( IPC_shared_memory , & IPC_handle , & IPC_handle_size );
379
+ if ( umf_result != UMF_RESULT_SUCCESS ) {
380
+ fprintf ( stderr , "[producer] ERROR: getting the IPC handle failed\n" );
371
381
goto err_free_IPC_shared_memory ;
372
382
}
373
383
374
- // zero the IPC handle and the shared memory
375
- memset (IPC_handle , 0 , IPC_handle_size );
376
-
377
384
// save a random number (&provider) in the shared memory
378
385
unsigned long long SHM_number_1 = (unsigned long long )& provider ;
379
386
memcopy_callback (IPC_shared_memory , & SHM_number_1 , sizeof (SHM_number_1 ),
@@ -382,16 +389,6 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
382
389
fprintf (stderr , "[producer] My shared memory contains a number: %llu\n" ,
383
390
SHM_number_1 );
384
391
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
392
fprintf (stderr , "[producer] Got the IPC handle\n" );
396
393
397
394
producer_socket = producer_connect (port );
@@ -494,22 +491,25 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
494
491
close (producer_socket );
495
492
496
493
err_PutIPCHandle :
497
- umf_result = umfMemoryProviderPutIPCHandle ( provider , IPC_handle );
494
+ umf_result = umfPutIPCHandle ( IPC_handle );
498
495
if (umf_result != UMF_RESULT_SUCCESS ) {
499
496
fprintf (stderr , "[producer] ERROR: putting the IPC handle failed\n" );
500
497
}
501
498
502
499
fprintf (stderr , "[producer] Put the IPC handle\n" );
503
500
504
- err_free_IPC_handle :
505
- free (IPC_handle );
506
501
err_free_IPC_shared_memory :
507
- (void )umfMemoryProviderFree ( provider , IPC_shared_memory ,
508
- size_IPC_shared_memory );
502
+ (void )umfFree ( IPC_shared_memory );
503
+
509
504
err_free_ptr2 :
510
- (void )umfMemoryProviderFree (provider , ptr2 , ptr2_size );
505
+ (void )umfFree (ptr2 );
506
+
511
507
err_free_ptr1 :
512
- (void )umfMemoryProviderFree (provider , ptr1 , ptr1_size );
508
+ (void )umfFree (ptr1 );
509
+
510
+ err_umfMemoryPoolDestroy :
511
+ umfPoolDestroy (pool );
512
+
513
513
err_umfMemoryProviderDestroy :
514
514
umfMemoryProviderDestroy (provider );
515
515
0 commit comments