@@ -97,9 +97,13 @@ class FMQUnsynchronizedPoolMemoryResource : public boost::container::pmr::memory
9797 mRegion = pChan.Transport ()->CreateUnmanagedRegion (
9898 pSize,
9999 pRegionFlags,
100- [this ](void * pRelData, size_t pRelSize, void * /* hint */ ) {
100+ [this ](const std::vector<FairMQRegionBlock>& pBlkVect ) {
101101 // callback to be called when message buffers no longer needed by transport
102- reclaimSHMMessage (pRelData, pRelSize);
102+ std::scoped_lock lock (mReclaimLock );
103+
104+ for (const auto &lBlk : pBlkVect) {
105+ reclaimSHMMessage (lBlk.ptr , lBlk.size );
106+ }
103107 },
104108 lSegmentRoot.c_str (),
105109 lMapFlags
@@ -217,8 +221,6 @@ class FMQUnsynchronizedPoolMemoryResource : public boost::container::pmr::memory
217221 {
218222 (void ) pSize;
219223 assert (pSize == mObjectSize );
220-
221- std::scoped_lock lock (mReclaimLock );
222224 mReclaimedObjects .push_back (pData);
223225 }
224226
@@ -290,9 +292,13 @@ class RegionAllocatorResource : public boost::container::pmr::memory_resource
290292 mRegion = pChan.Transport ()->CreateUnmanagedRegion (
291293 pSize,
292294 pRegionFlags,
293- [this ](void * pRelData, size_t pRelSize, void * /* hint */ ) {
294- // callback to be called when message buffers no longer needed by transport
295- reclaimSHMMessage (pRelData, pRelSize);
295+ [this ](const std::vector<FairMQRegionBlock>& pBlkVect) {
296+ // callback to be called when message buffers no longer needed by transports
297+ std::scoped_lock lock (mReclaimLock );
298+
299+ for (const auto &lBlk : pBlkVect) {
300+ reclaimSHMMessage (lBlk.ptr , lBlk.size );
301+ }
296302 },
297303 lSegmentRoot.c_str (),
298304 lMapFlags
@@ -336,7 +342,7 @@ class RegionAllocatorResource : public boost::container::pmr::memory_resource
336342
337343 virtual void * do_allocate (std::size_t pSize, std::size_t /* pAlign */ ) override final
338344 {
339- unsigned long lAllocAttempt= 0 ;
345+ unsigned long lAllocAttempt = 0 ;
340346
341347 // align up
342348 pSize = align_size_up (pSize);
@@ -369,6 +375,7 @@ class RegionAllocatorResource : public boost::container::pmr::memory_resource
369375 virtual void do_deallocate (void *pAddr, std::size_t pSize, std::size_t ) override final
370376 {
371377 // Objects are only freed through SHM message reclaim callback.
378+ std::scoped_lock lock (mReclaimLock );
372379 reclaimSHMMessage (pAddr, pSize);
373380 }
374381
@@ -394,16 +401,17 @@ class RegionAllocatorResource : public boost::container::pmr::memory_resource
394401
395402 bool try_reclaim (const std::size_t pSize) {
396403 // First declare any leftover memory as free
404+ std::scoped_lock lock (mReclaimLock );
405+
397406 if (mLength > 0 ) {
398407 assert (mStart != nullptr );
408+ // NOTE: caller must hold mReclaimLock lock
399409 reclaimSHMMessage (mStart , mLength );
400410 // invalidate the working extent
401411 mLength = 0 ;
402412 mStart = nullptr ;
403413 }
404414
405- std::scoped_lock lock (mReclaimLock );
406-
407415 if (mFrees .empty ()) {
408416 return false ;
409417 }
@@ -432,8 +440,6 @@ class RegionAllocatorResource : public boost::container::pmr::memory_resource
432440
433441 const char *lData = reinterpret_cast <const char *>(pData);
434442
435- std::scoped_lock lock (mReclaimLock );
436-
437443 // push object to the free map. Try to merge nodes
438444 const auto lIter = mFrees .lower_bound (lData);
439445 bool lInserted = false ;
0 commit comments