summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/memory.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/memory.cpp b/src/memory.cpp
index daaba8d..ce2fe00 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -1,6 +1,8 @@
#include "memory.hpp"
+#include <mutex>
+
const std::size_t MINIMUM_ALIGNMENT = 1;
const std::size_t MAXIMUM_ALIGNMENT = 64;
@@ -18,6 +20,7 @@ struct MemBucket {
int64_t maxBlockCount;
char *blocks;
char *ptr;
+ std::mutex mtx;
bool transient;
};
@@ -76,6 +79,7 @@ void *Pke_New(std::size_t sz, std::size_t alignment, MemBucket *bkt) {
long index = -1;
MemBlock *block = nullptr;
void *data = nullptr;
+ bkt->mtx.lock();
for (int64_t i = 0; i <= bkt->lastEmptyBlockIndex; ++i) {
auto &blk = blocks[i];
misalignment = reinterpret_cast<std::size_t>(blk.data) % calculatedAlignment;
@@ -152,6 +156,7 @@ void *Pke_New(std::size_t sz, std::size_t alignment, MemBucket *bkt) {
bkt->allocs++;
assert(data >= bkt->ptr && "allocated data is before bucket data");
assert(data <= bkt->ptr + bkt->size && "allocated data is after bucket data");
+ bkt->mtx.unlock();
return data;
}