diff options
author | 2015-03-09 12:15:53 -0700 | |
---|---|---|
committer | 2015-03-09 12:15:53 -0700 | |
commit | 5baedd637806293e9da600af42ada8f75e7db580 (patch) | |
tree | 1f615014c9411855495c08f7c81f03f779ad117b /src/gpu/GrBatch.cpp | |
parent | d2737ad7dd8f4ea94a74034027014fd3d78923cb (diff) |
Use global GrMemoryPools protected by mutex for GrProcessor/GrBatch
BUG=chromium:464892
Review URL: https://codereview.chromium.org/991943002
Diffstat (limited to 'src/gpu/GrBatch.cpp')
-rw-r--r-- | src/gpu/GrBatch.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/gpu/GrBatch.cpp b/src/gpu/GrBatch.cpp index e1650a6bd3..4df765e7b2 100644 --- a/src/gpu/GrBatch.cpp +++ b/src/gpu/GrBatch.cpp @@ -1,35 +1,38 @@ #include "GrBatch.h" #include "GrMemoryPool.h" -#include "SkTLS.h" +#include "SkMutex.h" // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small, // but seems to be mostly consistent. There is a lot in flux right now, but we should really // revisit this when batch is everywhere -class GrBatch_Globals { + +// We use a global pool protected by a mutex. Chrome may use the same GrContext on different +// threads. The GrContext is not used concurrently on different threads and there is a memory +// barrier between accesses of a context on different threads. Also, there may be multiple +// GrContexts and those contexts may be in use concurrently on different threads. +namespace { +SK_DECLARE_STATIC_MUTEX(gBatchPoolMutex); +class MemoryPoolAccessor { public: - static GrMemoryPool* GetTLS() { - return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); - } + MemoryPoolAccessor() { gBatchPoolMutex.acquire(); } -private: - static void* CreateTLS() { - return SkNEW_ARGS(GrMemoryPool, (16384, 16384)); - } + ~MemoryPoolAccessor() { gBatchPoolMutex.release(); } - static void DeleteTLS(void* pool) { - SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); + GrMemoryPool* pool() const { + static GrMemoryPool gPool(16384, 16384); + return &gPool; } }; +} -int32_t GrBatch::gCurrBatchClassID = - GrBatch::kIllegalBatchClassID; +int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchClassID; void* GrBatch::operator new(size_t size) { - return GrBatch_Globals::GetTLS()->allocate(size); + return MemoryPoolAccessor().pool()->allocate(size); } void GrBatch::operator delete(void* target) { - GrBatch_Globals::GetTLS()->release(target); + return MemoryPoolAccessor().pool()->release(target); } |