Title: [208482] trunk/Source/WTF
Revision
208482
Author
[email protected]
Date
2016-11-09 13:42:33 -0800 (Wed, 09 Nov 2016)

Log Message

Allow RefPtrs of const ThreadSafeRefCounted types
https://bugs.webkit.org/show_bug.cgi?id=164548

Patch by Alex Christensen <[email protected]> on 2016-11-09
Reviewed by Tim Horton.

* wtf/ThreadSafeRefCounted.h:
Make m_refCount mutable like we did with RefCounted in r203257.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (208481 => 208482)


--- trunk/Source/WTF/ChangeLog	2016-11-09 21:33:23 UTC (rev 208481)
+++ trunk/Source/WTF/ChangeLog	2016-11-09 21:42:33 UTC (rev 208482)
@@ -1,3 +1,13 @@
+2016-11-09  Alex Christensen  <[email protected]>
+
+        Allow RefPtrs of const ThreadSafeRefCounted types
+        https://bugs.webkit.org/show_bug.cgi?id=164548
+
+        Reviewed by Tim Horton.
+
+        * wtf/ThreadSafeRefCounted.h:
+        Make m_refCount mutable like we did with RefCounted in r203257.
+
 2016-11-09  Chris Dumez  <[email protected]>
 
         [Mac] Stop using deprecated AppKit enumeration values

Modified: trunk/Source/WTF/wtf/ThreadSafeRefCounted.h (208481 => 208482)


--- trunk/Source/WTF/wtf/ThreadSafeRefCounted.h	2016-11-09 21:33:23 UTC (rev 208481)
+++ trunk/Source/WTF/wtf/ThreadSafeRefCounted.h	2016-11-09 21:42:33 UTC (rev 208482)
@@ -23,8 +23,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ThreadSafeRefCounted_h
-#define ThreadSafeRefCounted_h
+#pragma once
 
 #include <atomic>
 #include <wtf/FastMalloc.h>
@@ -36,22 +35,19 @@
     WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedBase);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    ThreadSafeRefCountedBase(int initialRefCount = 1)
-        : m_refCount(initialRefCount)
-    {
-    }
+    ThreadSafeRefCountedBase() = default;
 
-    void ref()
+    void ref() const
     {
         ++m_refCount;
     }
 
-    bool hasOneRef()
+    bool hasOneRef() const
     {
         return refCount() == 1;
     }
 
-    int refCount() const
+    unsigned refCount() const
     {
         return m_refCount;
     }
@@ -58,35 +54,27 @@
 
 protected:
     // Returns whether the pointer should be freed or not.
-    bool derefBase()
+    bool derefBase() const
     {
-        if (--m_refCount <= 0) {
-            return true;
-        }
-
-        return false;
+        return !--m_refCount;
     }
 
 private:
-    std::atomic<int> m_refCount;
+    mutable std::atomic<unsigned> m_refCount { 1 };
 };
 
 template<class T> class ThreadSafeRefCounted : public ThreadSafeRefCountedBase {
 public:
-    void deref()
+    void deref() const
     {
         if (derefBase())
-            delete static_cast<T*>(this);
+            delete static_cast<const T*>(this);
     }
 
 protected:
-    ThreadSafeRefCounted()
-    {
-    }
+    ThreadSafeRefCounted() = default;
 };
 
 } // namespace WTF
 
 using WTF::ThreadSafeRefCounted;
-
-#endif // ThreadSafeRefCounted_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to