/* * Copyright (C) 2005-2018 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later * See LICENSES/README.md for more information. */ #pragma once #include #include template struct IDVDResourceCounted { IDVDResourceCounted() : m_refs(1) {} virtual ~IDVDResourceCounted() = default; IDVDResourceCounted(const IDVDResourceCounted &) = delete; IDVDResourceCounted &operator=(const IDVDResourceCounted &) = delete; virtual T* Acquire() { ++m_refs; return static_cast(this); } virtual long Release() { long count = --m_refs; assert(count >= 0); if (count == 0) delete static_cast(this); return count; } std::atomic m_refs; };