4040
4141#include " GPULogging.h"
4242#include " utils/strtag.h"
43+ #include " utils/stdspinlock.h"
4344
4445#ifdef GPUCA_O2_LIB
4546#include " GPUO2InterfaceConfiguration.h"
@@ -589,6 +590,7 @@ size_t GPUReconstruction::AllocateRegisteredMemoryHelper(GPUMemoryResource* res,
589590 throw std::bad_alloc ();
590591 }
591592 size_t retVal;
593+ stdspinlock spinlock (mMemoryMutex );
592594 if ((res->mType & GPUMemoryResource::MEMORY_STACK) && memorypoolend) {
593595 retVal = ptrDiff ((res->*setPtr)((char *)1 ), (char *)(1 ));
594596 memorypoolend = (void *)((char *)memorypoolend - GPUProcessor::getAlignmentMod<GPUCA_MEMALIGN>(memorypoolend));
@@ -642,6 +644,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
642644 std::cout << (res->mReuse >= 0 ? " Reused " : " Allocated " ) << res->mName << " : " << res->mSize << " (individual" << ((res->mType & GPUMemoryResource::MEMORY_STACK) ? " stack" : " " ) << " )\n " ;
643645 }
644646 if (res->mType & GPUMemoryResource::MEMORY_STACK) {
647+ stdspinlock spinlock (mMemoryMutex );
645648 mNonPersistentIndividualAllocations .emplace_back (res);
646649 }
647650 if ((size_t )res->mPtr % GPUCA_BUFFER_ALIGNMENT) {
@@ -722,6 +725,7 @@ size_t GPUReconstruction::AllocateRegisteredMemory(int16_t ires, GPUOutputContro
722725
723726void * GPUReconstruction::AllocateDirectMemory (size_t size, int32_t type)
724727{
728+ stdspinlock spinlock (mMemoryMutex );
725729 if (GetProcessingSettings ().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
726730 char * retVal = new (std::align_val_t (GPUCA_BUFFER_ALIGNMENT)) char [size];
727731 if ((type & GPUMemoryResource::MEMORY_STACK)) {
@@ -763,6 +767,7 @@ void* GPUReconstruction::AllocateDirectMemory(size_t size, int32_t type)
763767
764768void * GPUReconstruction::AllocateVolatileDeviceMemory (size_t size)
765769{
770+ stdspinlock spinlock (mMemoryMutex );
766771 if (mVolatileMemoryStart == nullptr ) {
767772 mVolatileMemoryStart = mDeviceMemoryPool ;
768773 }
@@ -788,6 +793,7 @@ void* GPUReconstruction::AllocateVolatileMemory(size_t size, bool device)
788793 return AllocateVolatileDeviceMemory (size);
789794 }
790795 char * retVal = new (std::align_val_t (GPUCA_BUFFER_ALIGNMENT)) char [size];
796+ stdspinlock spinlock (mMemoryMutex );
791797 mVolatileChunks .emplace_back (retVal, alignedDeleter ());
792798 return retVal;
793799}
@@ -912,6 +918,7 @@ void GPUReconstruction::PopNonPersistentMemory(RecoStep step, uint64_t tag, cons
912918 res->mPtrDevice = nullptr ;
913919 }
914920 if (!proc) {
921+ stdspinlock spinlock (mMemoryMutex );
915922 mHostMemoryPoolEnd = std::get<0 >(mNonPersistentMemoryStack .back ());
916923 mDeviceMemoryPoolEnd = std::get<1 >(mNonPersistentMemoryStack .back ());
917924 mNonPersistentIndividualAllocations .resize (std::get<2 >(mNonPersistentMemoryStack .back ()));
0 commit comments