diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/interfaces/legacy/AddonClass.cpp | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/interfaces/legacy/AddonClass.cpp')
-rw-r--r-- | xbmc/interfaces/legacy/AddonClass.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/xbmc/interfaces/legacy/AddonClass.cpp b/xbmc/interfaces/legacy/AddonClass.cpp new file mode 100644 index 0000000..ffdf3d4 --- /dev/null +++ b/xbmc/interfaces/legacy/AddonClass.cpp @@ -0,0 +1,90 @@ +/* + * 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. + */ + +#include "AddonClass.h" +#ifdef XBMC_ADDON_DEBUG_MEMORY +#include "utils/log.h" +#endif +#include "LanguageHook.h" +#include "AddonUtils.h" + +using namespace XBMCAddonUtils; + +namespace XBMCAddon +{ + // need a place to put the vtab + AddonClass::~AddonClass() + { + m_isDeallocating= true; + + if (languageHook != NULL) + languageHook->Release(); + +#ifdef XBMC_ADDON_DEBUG_MEMORY + isDeleted = false; +#endif + } + + AddonClass::AddonClass() : refs(0L), + languageHook(NULL) + { +#ifdef XBMC_ADDON_DEBUG_MEMORY + isDeleted = false; +#endif + + // check to see if we have a language hook that was prepared for this instantiation + languageHook = LanguageHook::GetLanguageHook(); + if (languageHook != NULL) + { + languageHook->Acquire(); + + // here we assume the language hook was set for the single instantiation of + // this AddonClass (actually - its subclass - but whatever). So we + // will now reset the Tls. This avoids issues if the constructor of the + // subclass throws an exception. + LanguageHook::ClearLanguageHook(); + } + } + +#ifdef XBMC_ADDON_DEBUG_MEMORY + void AddonClass::Release() const + { + if (isDeleted) + CLog::Log(LOGERROR, "NEWADDON REFCNT Releasing dead class {} 0x{:x}", GetClassname(), + (long)(((void*)this))); + + long ct = --refs; +#ifdef LOG_LIFECYCLE_EVENTS + CLog::Log(LOGDEBUG, "NEWADDON REFCNT decrementing to {} on {} 0x{:x}", refs.load(), + GetClassname(), (long)(((void*)this))); +#endif + if(ct == 0) + { + const_cast<AddonClass*>(this)->isDeleted = true; + // we're faking a delete but not doing it so call the destructor explicitly + this->~AddonClass(); + } + } + + void AddonClass::Acquire() const + { + if (isDeleted) + CLog::Log(LOGERROR, "NEWADDON REFCNT Acquiring dead class {} 0x{:x}", GetClassname(), + (long)(((void*)this))); + +#ifdef LOG_LIFECYCLE_EVENTS + CLog::Log(LOGDEBUG, "NEWADDON REFCNT incrementing to {} on {} 0x{:x}", ++refs, GetClassname(), + (long)(((void*)this))); +#else + ++refs; +#endif + } +#endif +} + + |