diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Allocator/DualThreadAllocator.h |
Diffstat (limited to 'Runtime/Allocator/DualThreadAllocator.h')
-rw-r--r-- | Runtime/Allocator/DualThreadAllocator.h | 55 |
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 |