/* * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. * */ #pragma once #include #include #include #include #include namespace facebook { class Countable : public noncopyable, public nonmovable { public: // RefPtr expects refcount to start at 0 Countable() : m_refcount(0) {} virtual ~Countable() { FBASSERT(m_refcount == 0); } private: void ref() { ++m_refcount; } void unref() { if (0 == --m_refcount) { delete this; } } bool hasOnlyOneRef() const { return m_refcount == 1; } template friend class RefPtr; std::atomic m_refcount; }; }