Skip to content
Snippets Groups Projects
Commit d33cd06f authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[MemoryManager] Free the memory in the queues and the queues on destruction

parent 99092a76
No related branches found
No related tags found
1 merge request!339Memory manager
......@@ -14,6 +14,8 @@ class MemoryManager {
private:
const workerid_t workerCount;
adt::BoundedBumpArray<void, WORKER_EXCLUSIVE_QUEUE_SIZE>** workerExclusiveQueues;
adt::WsClQueue<void*, WS_QUEUE_SIZE>** queues;
static thread_local adt::BoundedBumpArray<void, WORKER_EXCLUSIVE_QUEUE_SIZE> workerExclusiveQueue;
......@@ -32,6 +34,8 @@ class MemoryManager {
public:
MemoryManager(Runtime& runtime);
~MemoryManager();
auto getMemory(bool* malloced) -> void* {
*malloced = false;
void* memory = workerExclusiveQueue.get();
......@@ -88,7 +92,28 @@ template <typename T, intptr_t WS_QUEUE_SIZE, size_t WORKER_EXCLUSIVE_QUEUE_SIZE
MemoryManager<T, WS_QUEUE_SIZE, WORKER_EXCLUSIVE_QUEUE_SIZE>::MemoryManager(Runtime& runtime)
: workerCount(runtime.getWorkerCount()) {
queues = new adt::WsClQueue<void*, WS_QUEUE_SIZE>*[workerCount];
workerExclusiveQueues =
new adt::BoundedBumpArray<void, WORKER_EXCLUSIVE_QUEUE_SIZE>*[workerCount];
auto newWorkerHook = [this](workerid_t workerId) { queues[workerId] = &queue; };
auto newWorkerHook = [this](workerid_t workerId) {
workerExclusiveQueues[workerId] = &workerExclusiveQueue;
queues[workerId] = &queue;
};
runtime.addNewWorkerHook(newWorkerHook);
}
template <typename T, intptr_t WS_QUEUE_SIZE, size_t WORKER_EXCLUSIVE_QUEUE_SIZE>
MemoryManager<T, WS_QUEUE_SIZE, WORKER_EXCLUSIVE_QUEUE_SIZE>::~MemoryManager() {
for (workerid_t i = 0; i < workerCount; ++i) {
auto* queue = workerExclusiveQueues[i];
while (auto* mem = queue->get()) free(mem);
}
delete workerExclusiveQueues;
for (workerid_t i = 0; i < workerCount; ++i) {
auto* queue = queues[i];
void* mem;
while (queue->popBottom(&mem)) free(mem);
}
delete queues;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment