You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implemented parallelism-compatibility by adding a global mutex that is locked and unlocked for every critical section in the code (in check, init, malloc, free, and realloc). Runs fine with cache-scratch (fixed segfault-causing bug). Also runs fine with mdriver (though throughput has fallen to 32 from 40).
// std::cout<<" that had an internal size of "<<mb->size - TOTAL_BLOCK_OVERHEAD<<", an aligned size (incl. overhead) of "<<mb->size<<", and a new requested size of "<<size;
@@ -338,6 +362,7 @@ namespace my {
338
362
truncateMemoryBlock(mb, alignedSize);
339
363
// std::cout<<"\nReallocated by truncating to aligned size. \nNew state of memory: ";
340
364
// printStateOfMemory();
365
+
GLOBAL_UNLOCK;
341
366
returnMEMORY_LOCATION_TO_RETURN(mb);
342
367
}
343
368
if (alignedSize > mb->size) {
@@ -349,23 +374,27 @@ namespace my {
349
374
truncateMemoryBlock(mb, alignedSize);
350
375
// std::cout<<"\nReallocated by using adjacent free block on right. \nNew state of memory: ";
351
376
// printStateOfMemory();
377
+
GLOBAL_UNLOCK;
352
378
returnMEMORY_LOCATION_TO_RETURN(mb);
353
379
}
354
380
else {
355
381
void * newptr = malloc(size);
356
382
if (!newptr) {
383
+
GLOBAL_UNLOCK;
357
384
returnNULL;
358
385
}
359
386
size_t copy_size = mb->size - TOTAL_BLOCK_OVERHEAD; // internal size of the original memory block
360
387
copy_size = (size < copy_size)? size : copy_size; // if the new size is less that the original internal size, we MUST NOT copy more than new size bytes to the new block
361
388
std::memcpy(newptr, ptr, copy_size);
362
389
free(ptr);
363
390
// std::cout<<"\nReallocated by calling malloc and free. Had to copy "<<copy_size<<" bytes using memcpy. \nNew state of memory: ";
364
-
// printStateOfMemory();
391
+
// printStateOfMemory();
392
+
GLOBAL_UNLOCK;
365
393
return newptr;
366
394
}
367
395
}
368
396
// std::cout<<"\nReturning original pointer as new alignedSize == original aligned size of memory block.";
0 commit comments