2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/log.h"
16 int CXHandle::m_objectTracker
[10] = {};
18 HANDLE WINAPI
GetCurrentProcess(void) {
19 return (HANDLE
)-1; // -1 a special value - pseudo handle
25 m_objectTracker
[m_type
]++;
28 CXHandle::CXHandle(HandleType nType
)
32 m_objectTracker
[m_type
]++;
35 CXHandle::CXHandle(const CXHandle
&src
)
37 // we shouldn't get here EVER. however, if we do - try to make the best. copy what we can
38 // and most importantly - not share any pointer.
39 CLog::Log(LOGWARNING
, "{}, copy handle.", __FUNCTION__
);
44 m_hMutex
= new CCriticalSection();
47 m_bManualEvent
= src
.m_bManualEvent
;
48 m_tmCreation
= time(NULL
);
49 m_FindFileResults
= src
.m_FindFileResults
;
50 m_nFindFileIterator
= src
.m_nFindFileIterator
;
51 m_FindFileDir
= src
.m_FindFileDir
;
52 m_iOffset
= src
.m_iOffset
;
53 m_bCDROM
= src
.m_bCDROM
;
54 m_objectTracker
[m_type
]++;
60 m_objectTracker
[m_type
]--;
62 if (RecursionCount
> 0) {
63 CLog::Log(LOGERROR
, "{}, destroying handle with recursion count {}", __FUNCTION__
,
68 if (m_nRefCount
> 1) {
69 CLog::Log(LOGERROR
, "{}, destroying handle with ref count {}", __FUNCTION__
, m_nRefCount
);
78 delete m_internalLock
;
100 m_nFindFileIterator
=0 ;
102 m_tmCreation
= time(NULL
);
103 m_internalLock
= new CCriticalSection();
106 void CXHandle::ChangeType(HandleType newType
) {
107 m_objectTracker
[m_type
]--;
109 m_objectTracker
[m_type
]++;
112 void CXHandle::DumpObjectTracker() {
113 for (int i
=0; i
< 10; i
++) {
114 CLog::Log(LOGDEBUG
, "object {} --> {} instances", i
, m_objectTracker
[i
]);
118 bool CloseHandle(HANDLE hObject
) {
122 if (hObject
== INVALID_HANDLE_VALUE
|| hObject
== (HANDLE
)-1)
125 bool bDelete
= false;
127 std::unique_lock
<CCriticalSection
> lock((*hObject
->m_internalLock
));
128 if (--hObject
->m_nRefCount
== 0)