Index: include/core/SkRefCnt.h |
=================================================================== |
--- include/core/SkRefCnt.h (revision 10052) |
+++ include/core/SkRefCnt.h (working copy) |
@@ -41,10 +41,30 @@ |
#endif |
} |
- /** Return the reference count. |
- */ |
- int32_t getRefCnt() const { return fRefCnt; } |
+ /** Return the reference count. Use only for debugging. */ |
bsalomon
2013/07/15 13:04:08
It seems a little weird that these obviously call
bungeman-skia
2013/07/15 16:02:41
I believe that with this change this is only used
|
+ int32_t getRefCnt() const { return sk_atomic_unprotected_read(fRefCnt); } |
+ /** Returns true if the caller is the only owner. |
+ * |
+ * This provides no memory barriers. |
+ * |
+ * Using the object without additional memory barriers when this returns |
+ * true is safe so long as the object is only modified when this returns |
+ * true and the caller is still the only owner. This is true in the usual |
+ * case of optimizing copy on write semantics. |
+ * |
+ * If other threads may have modified the object (even within a mutex), |
+ * then an acquire barrier (L/SL) is required before using the object |
+ * (may already be provided by the load in unique() on some platforms). |
+ * Without this barrier, modifications to the object made by the other |
+ * thread may not yet be visible or complete on the current thread. |
+ */ |
+ bool unique() const { |
Alexander Potapenko
2013/07/15 15:05:34
I suggest to add an sk_atomic_acquire_load() funct
bungeman-skia
2013/07/15 16:02:41
Yes, this is addressed in the comment above. Addin
Alexander Potapenko
2013/07/16 14:03:30
Yes, I was talking about false positives from TSan
bungeman-skia
2013/07/16 15:50:57
All writes here are atomic. The entire point of th
|
+ // sk_atomic_unprotected_read forces an atomic read of fRefCnt and |
+ // marks the read has a benign race with ref() and unref(). |
+ return (1 == sk_atomic_unprotected_read(fRefCnt)); |
Dmitry Vyukov
2013/07/16 13:17:51
sk_atomic_unprotected_read() needs to use Acquire_
bungeman-skia
2013/07/16 15:50:57
I've tried to clarify via email, but nothing inter
|
+ } |
+ |
/** Increment the reference count. Must be balanced by a call to unref(). |
*/ |
void ref() const { |
@@ -72,16 +92,6 @@ |
} |
/** |
- * Alias for ref(), for compatibility with scoped_refptr. |
- */ |
- void AddRef() { this->ref(); } |
- |
- /** |
- * Alias for unref(), for compatibility with scoped_refptr. |
- */ |
- void Release() { this->unref(); } |
- |
- /** |
* Alias for unref(), for compatibility with WTF::RefPtr. |
*/ |
void deref() { this->unref(); } |
@@ -109,9 +119,10 @@ |
SkDELETE(this); |
} |
+ // The following friends are those which override internal_dispose() |
+ // and conditionally call SkRefCnt::internal_dispose(). |
+ friend class GrTexture; |
friend class SkWeakRefCnt; |
- friend class GrTexture; // to allow GrTexture's internal_dispose to |
- // call SkRefCnt's & directly set fRefCnt (to 1) |
mutable int32_t fRefCnt; |