*/
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);
#endif // SK_LAZY_CACHE_STATS
private:
- SkBaseMutex* fMutex;
+ SkMutex fMutex;
size_t fBudget;
size_t fUsed;
SkTInternalLList<PoolDiscardableMemory> fList;
////////////////////////////////////////////////////////////////////////////////
-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;
}
void DiscardableMemoryPool::dumpDownTo(size_t budget) {
- if (fMutex != nullptr) {
- fMutex->assertHeld();
- }
+ fMutex.assertHeld();
if (fUsed <= budget) {
return;
}
} // 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;
}
/**
* This non-global pool can be used for unit tests to verify that
* the pool works.
- * Without mutex, will be not be thread safe.
*/
- static sk_sp<SkDiscardableMemoryPool> Make(size_t size, SkBaseMutex* mutex = nullptr);
+ static sk_sp<SkDiscardableMemoryPool> Make(size_t size);
};
/**
#include "Test.h"
DEF_TEST(DiscardableMemoryPool, reporter) {
- sk_sp<SkDiscardableMemoryPool> pool(
- SkDiscardableMemoryPool::Make(1, nullptr));
+ sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(1));
pool->setRAMBudget(3);
REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
DEF_TEST(DiscardableMemory_nonglobal, reporter) {
sk_sp<SkDiscardableMemoryPool> pool(
- SkDiscardableMemoryPool::Make(1024, /* mutex = */ nullptr));
+ SkDiscardableMemoryPool::Make(1024));
std::unique_ptr<SkDiscardableMemory> dm(pool->create(kTestStringLength));
test_dm(reporter, dm.get(), true);
}
test_cache(reporter, cache, true);
}
{
- sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(defLimit, nullptr));
+ sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(defLimit));
gPool = pool.get();
SkResourceCache cache(pool_factory);
test_cache(reporter, cache, true);
testBitmapCache_discarded_bitmap(reporter, &cache, nullptr);
}
{
- sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(byteLimit, nullptr));
+ sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(byteLimit));
gPool = pool.get();
SkResourceCache::DiscardableFactory factory = pool_factory;
SkResourceCache cache(factory);