summaryrefslogtreecommitdiff
path: root/Runtime/Allocator/DualThreadAllocator.h
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Allocator/DualThreadAllocator.h')
-rw-r--r--Runtime/Allocator/DualThreadAllocator.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/Runtime/Allocator/DualThreadAllocator.h b/Runtime/Allocator/DualThreadAllocator.h
new file mode 100644
index 0000000..089b4ca
--- /dev/null
+++ b/Runtime/Allocator/DualThreadAllocator.h
@@ -0,0 +1,55 @@
+#ifndef DUALTHREAD_ALLOCATOR_H_
+#define DUALTHREAD_ALLOCATOR_H_
+
+#if ENABLE_MEMORY_MANAGER
+
+#include "Runtime/Allocator/BaseAllocator.h"
+#include "Runtime/Threads/ThreadSpecificValue.h"
+
+class DelayedPointerDeletionManager;
+
+// Dual Thread Allocator is an indirection to a real allocator
+
+// Has pointer to the main allocator (nonlocking)
+// Has pointer to the shared thread allocator (locking)
+
+template <class UnderlyingAllocator>
+class DualThreadAllocator : public BaseAllocator
+{
+public:
+ // when constructing it will be from the main thread
+ DualThreadAllocator(const char* name, BaseAllocator* mainAllocator, BaseAllocator* threadAllocator);
+ virtual ~DualThreadAllocator() {}
+
+ virtual void* Allocate(size_t size, int align);
+ virtual void* Reallocate (void* p, size_t size, int align);
+ virtual void Deallocate (void* p);
+ virtual bool Contains (const void* p);
+
+ virtual size_t GetAllocatedMemorySize() const;
+ virtual size_t GetAllocatorSizeTotalUsed() const;
+ virtual size_t GetReservedSizeTotal() const;
+
+ virtual size_t GetPtrSize(const void* ptr) const;
+ virtual ProfilerAllocationHeader* GetProfilerHeader(const void* ptr) const;
+
+ virtual void ThreadCleanup();
+
+ virtual bool CheckIntegrity();
+ virtual bool ValidatePointer(void* ptr);
+
+ bool TryDeallocate (void* p);
+
+ virtual void FrameMaintenance(bool cleanup);
+
+private:
+ UnderlyingAllocator* GetCurrentAllocator();
+
+ UnderlyingAllocator* m_MainAllocator;
+ UnderlyingAllocator* m_ThreadAllocator;
+
+ DelayedPointerDeletionManager* m_DelayedDeletion;
+};
+
+#endif
+#endif