1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
}
|