aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-19 23:18:52 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-19 23:18:52 +0000
commitf64c6842c15e1ba126639be7578e4642cb396987 (patch)
tree4d7091db554b6a61ce197cbf4ff4ebc2980dbf2d /src/gpu
parent13388e71645caa3e223a3b024efe103f7110f1a9 (diff)
Add a 'unique' method to SkRefCnt, document the usage, and add support.
std::shared_ptr has a method called 'unique' which captures the concept that a reference count of 1 is special, and can be used to optimize copy on write. It also has some undocumented need for memory barriers in certain situations and those needs are documented here. The motivation for looking into this is crbug.com/258499 . The use of the reference count in this manner is a benign race with both ref() and unref(). By introducing sk_atomic_unprotected_read, it is possible for Chromium to annotate this read to tell ThreadSanitizer that this is known. R=bsalomon@google.com Review URL: https://codereview.chromium.org/18770007 git-svn-id: http://skia.googlecode.com/svn/trunk@10221 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp2
-rw-r--r--src/gpu/GrEffect.cpp2
-rw-r--r--src/gpu/GrResourceCache.cpp4
3 files changed, 4 insertions, 4 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 64dbadf354..30cc6a3965 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -488,7 +488,7 @@ void GrContext::addExistingTextureToCache(GrTexture* texture) {
// Conceptually, the cache entry is going to assume responsibility
// for the creation ref.
- GrAssert(1 == texture->getRefCnt());
+ GrAssert(texture->unique());
// Since this texture came from an AutoScratchTexture it should
// still be in the exclusive pile
diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp
index 2aad7cf00e..22b38a371e 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -63,7 +63,7 @@ int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIl
SK_DEFINE_INST_COUNT(GrEffectRef)
GrEffectRef::~GrEffectRef() {
- GrAssert(1 == this->getRefCnt());
+ GrAssert(this->unique());
fEffect->EffectRefDestroyed();
fEffect->unref();
}
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 03a4e899db..96b11aaafe 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -164,7 +164,7 @@ void GrResourceCache::attachToHead(GrResourceEntry* entry,
class GrTFindUnreffedFunctor {
public:
bool operator()(const GrResourceEntry* entry) const {
- return 1 == entry->resource()->getRefCnt();
+ return entry->resource()->unique();
}
};
@@ -338,7 +338,7 @@ void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
}
GrResourceEntry* prev = iter.prev();
- if (1 == entry->fResource->getRefCnt()) {
+ if (entry->fResource->unique()) {
changed = true;
this->deleteResource(entry);
}