diff options
author | Hal Canary <halcanary@google.com> | 2017-04-25 08:58:57 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-05 15:10:13 +0000 |
commit | 788c3c467a019f31e6e2c6d07a7b644bc157bb34 (patch) | |
tree | 9eb51c34dd4f440507b81dbed4f5a96b0cd96e61 /src/lazy/SkDiscardableMemoryPool.cpp | |
parent | bc5d4d769098a4fb46685c0e59034dc8e12318a2 (diff) |
SkDiscardableMemoryPool: always have a mutex for testing
Change-Id: I898058f1125f62832f2b2b661c661efb0f84da6d
Reviewed-on: https://skia-review.googlesource.com/14274
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Diffstat (limited to 'src/lazy/SkDiscardableMemoryPool.cpp')
-rw-r--r-- | src/lazy/SkDiscardableMemoryPool.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/lazy/SkDiscardableMemoryPool.cpp b/src/lazy/SkDiscardableMemoryPool.cpp index aeba34bb04..6e5582a494 100644 --- a/src/lazy/SkDiscardableMemoryPool.cpp +++ b/src/lazy/SkDiscardableMemoryPool.cpp @@ -27,10 +27,7 @@ class PoolDiscardableMemory; */ class DiscardableMemoryPool : public SkDiscardableMemoryPool { public: - /** - * Without mutex, will be not be thread safe. - */ - DiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = nullptr); + DiscardableMemoryPool(size_t budget); ~DiscardableMemoryPool() override; std::unique_ptr<SkDiscardableMemory> make(size_t bytes); @@ -56,7 +53,7 @@ public: #endif // SK_LAZY_CACHE_STATS private: - SkBaseMutex* fMutex; + SkMutex fMutex; size_t fBudget; size_t fUsed; SkTInternalLList<PoolDiscardableMemory> fList; @@ -126,10 +123,8 @@ void PoolDiscardableMemory::unlock() { //////////////////////////////////////////////////////////////////////////////// -DiscardableMemoryPool::DiscardableMemoryPool(size_t budget, - SkBaseMutex* mutex) - : fMutex(mutex) - , fBudget(budget) +DiscardableMemoryPool::DiscardableMemoryPool(size_t budget) + : fBudget(budget) , fUsed(0) { #if SK_LAZY_CACHE_STATS fCacheHits = 0; @@ -144,9 +139,7 @@ DiscardableMemoryPool::~DiscardableMemoryPool() { } void DiscardableMemoryPool::dumpDownTo(size_t budget) { - if (fMutex != nullptr) { - fMutex->assertHeld(); - } + fMutex.assertHeld(); if (fUsed <= budget) { return; } @@ -236,14 +229,13 @@ void DiscardableMemoryPool::dumpPool() { } // namespace -sk_sp<SkDiscardableMemoryPool> SkDiscardableMemoryPool::Make(size_t size, SkBaseMutex* mutex) { - return sk_make_sp<DiscardableMemoryPool>(size, mutex); +sk_sp<SkDiscardableMemoryPool> SkDiscardableMemoryPool::Make(size_t size) { + return sk_make_sp<DiscardableMemoryPool>(size); } SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { - static SkBaseMutex gMutex; // Intentionally leak this global pool. static SkDiscardableMemoryPool* global = - new DiscardableMemoryPool(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE, &gMutex); + new DiscardableMemoryPool(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE); return global; } |