blob: 089b4ca435307990ded6bd98dbd768828a6be486 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
|