Chromium Code Reviews| Index: Source/wtf/text/StringImpl.h |
| diff --git a/Source/wtf/text/StringImpl.h b/Source/wtf/text/StringImpl.h |
| index 4c5fb01607778ad77ea6c7e7dec8cba0de257cd2..1682171712bf672c9520d02193ebcdee0ec5c3eb 100644 |
| --- a/Source/wtf/text/StringImpl.h |
| +++ b/Source/wtf/text/StringImpl.h |
| @@ -25,6 +25,7 @@ |
| #include <limits.h> |
| #include "wtf/ASCIICType.h" |
| +#include "wtf/DynamicAnnotations.h" |
| #include "wtf/Forward.h" |
| #include "wtf/HashMap.h" |
| #include "wtf/StringHasher.h" |
| @@ -283,24 +284,28 @@ public: |
| return hashSlowCase(); |
| } |
| + ALWAYS_INLINE unsigned refCount() const |
| + { |
| + return static_cast<int const volatile &>(m_refCount); |
| + } |
| + |
| ALWAYS_INLINE bool hasOneRef() const |
| { |
| - return m_refCount == 1; |
| + return refCount() == 1; |
| } |
| ALWAYS_INLINE void ref() |
| { |
| - ++m_refCount; |
| + atomicIncrement(&m_refCount); |
| } |
| ALWAYS_INLINE void deref() |
| { |
| - if (hasOneRef()) { |
| + WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount); |
| + if (atomicDecrement(&m_refCount) <= 0) { |
| + WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount); |
|
Alexander Potapenko
2014/12/08 11:46:57
Please do not use WTF_ANNOTATE_HAPPENS_AFTER.
They
|
| destroyIfNotStatic(); |
| - return; |
| } |
| - |
| - --m_refCount; |
| } |
| static StringImpl* empty(); |
| @@ -448,7 +453,7 @@ private: |
| #endif |
| private: |
| - unsigned m_refCount; |
| + int m_refCount; |
| unsigned m_length; |
| mutable unsigned m_hash : 24; |
| unsigned m_isAtomic : 1; |