diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WTF/wtf/DeferrableRefCounted.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WTF/wtf/DeferrableRefCounted.h')
-rw-r--r-- | Source/WTF/wtf/DeferrableRefCounted.h | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/Source/WTF/wtf/DeferrableRefCounted.h b/Source/WTF/wtf/DeferrableRefCounted.h index 6b9229769..796481a33 100644 --- a/Source/WTF/wtf/DeferrableRefCounted.h +++ b/Source/WTF/wtf/DeferrableRefCounted.h @@ -20,11 +20,10 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DeferrableRefCounted_h -#define DeferrableRefCounted_h +#pragma once #include <wtf/Assertions.h> #include <wtf/FastMalloc.h> @@ -41,39 +40,39 @@ namespace WTF { class DeferrableRefCountedBase { static const unsigned deferredFlag = 1; static const unsigned normalIncrement = 2; - + public: - void ref() + void ref() const { m_refCount += normalIncrement; } - + bool hasOneRef() const { return refCount() == 1; } - + unsigned refCount() const { return m_refCount / normalIncrement; } - + bool isDeferred() const { return !!(m_refCount & deferredFlag); } - + protected: DeferrableRefCountedBase() : m_refCount(normalIncrement) { } - + ~DeferrableRefCountedBase() { } - - bool derefBase() + + bool derefBase() const { m_refCount -= normalIncrement; return !m_refCount; @@ -88,21 +87,21 @@ protected: m_refCount &= ~deferredFlag; return !m_refCount; } - + private: - unsigned m_refCount; + mutable unsigned m_refCount; }; template<typename T> class DeferrableRefCounted : public DeferrableRefCountedBase { WTF_MAKE_NONCOPYABLE(DeferrableRefCounted); WTF_MAKE_FAST_ALLOCATED; public: - void deref() + void deref() const { if (derefBase()) - delete static_cast<T*>(this); + delete static_cast<const T*>(this); } - + bool setIsDeferred(bool value) { if (!setIsDeferredBase(value)) @@ -110,7 +109,7 @@ public: delete static_cast<T*>(this); return true; } - + protected: DeferrableRefCounted() { } ~DeferrableRefCounted() { } @@ -119,6 +118,3 @@ protected: } // namespace WTF using WTF::DeferrableRefCounted; - -#endif // DeferrableRefCounted_h - |