summaryrefslogtreecommitdiff
path: root/Runtime/Allocator/TLSAllocator.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Allocator/TLSAllocator.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Allocator/TLSAllocator.h')
-rw-r--r--Runtime/Allocator/TLSAllocator.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/Runtime/Allocator/TLSAllocator.h b/Runtime/Allocator/TLSAllocator.h
new file mode 100644
index 0000000..a7520ff
--- /dev/null
+++ b/Runtime/Allocator/TLSAllocator.h
@@ -0,0 +1,55 @@
+#ifndef TLS_ALLOCATOR_H_
+#define TLS_ALLOCATOR_H_
+
+#if ENABLE_MEMORY_MANAGER
+
+#include "Runtime/Allocator/BaseAllocator.h"
+#include "Runtime/Threads/ThreadSpecificValue.h"
+
+
+// TLS Allocator is an indirection to a real allocator
+// Has a tls value pointing to the threadspecific allocator if unique per thread.
+
+template <class UnderlyingAllocator>
+class TLSAllocator : public BaseAllocator
+{
+public:
+ // when constructing it will be from the main thread
+ TLSAllocator(const char* name);
+ virtual ~TLSAllocator();
+
+ 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 ThreadInitialize(BaseAllocator* allocator);
+ virtual void ThreadCleanup();
+
+ virtual bool CheckIntegrity();
+
+ virtual bool IsAssigned() const;
+ bool TryDeallocate (void* p);
+
+ UnderlyingAllocator* GetCurrentAllocator();
+ virtual void FrameMaintenance(bool cleanup);
+
+private:
+ // because TLS values have to be static on some platforms, this is made static
+ // and only one instance of the TLS is allowed
+ static UNITY_TLS_VALUE(UnderlyingAllocator*) m_UniqueThreadAllocator; // the memorymanager holds the list of allocators
+ static int s_NumberOfInstances;
+
+ static const int kMaxThreadTempAllocators = 128;
+ UnderlyingAllocator* m_ThreadTempAllocators[kMaxThreadTempAllocators];
+};
+
+#endif
+#endif