[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / platform / posix / XHandle.cpp
blobbe7a78bf4bed28553bb81f76e90b5b40cacb9da7
1 /*
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.
7 */
9 #include "XHandle.h"
11 #include "utils/log.h"
13 #include <cassert>
14 #include <mutex>
16 int CXHandle::m_objectTracker[10] = {};
18 HANDLE WINAPI GetCurrentProcess(void) {
19 return (HANDLE)-1; // -1 a special value - pseudo handle
22 CXHandle::CXHandle()
24 Init();
25 m_objectTracker[m_type]++;
28 CXHandle::CXHandle(HandleType nType)
30 Init();
31 m_type=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__);
41 Init();
43 if (src.m_hMutex)
44 m_hMutex = new CCriticalSection();
46 fd = src.fd;
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]++;
57 CXHandle::~CXHandle()
60 m_objectTracker[m_type]--;
62 if (RecursionCount > 0) {
63 CLog::Log(LOGERROR, "{}, destroying handle with recursion count {}", __FUNCTION__,
64 RecursionCount);
65 assert(false);
68 if (m_nRefCount > 1) {
69 CLog::Log(LOGERROR, "{}, destroying handle with ref count {}", __FUNCTION__, m_nRefCount);
70 assert(false);
73 if (m_hMutex) {
74 delete m_hMutex;
77 if (m_internalLock) {
78 delete m_internalLock;
81 if (m_hCond) {
82 delete m_hCond;
85 if ( fd != 0 ) {
86 close(fd);
91 void CXHandle::Init()
93 fd=0;
94 m_hMutex=NULL;
95 m_hCond=NULL;
96 m_type = HND_NULL;
97 RecursionCount=0;
98 m_bManualEvent=false;
99 m_bEventSet=false;
100 m_nFindFileIterator=0 ;
101 m_nRefCount=1;
102 m_tmCreation = time(NULL);
103 m_internalLock = new CCriticalSection();
106 void CXHandle::ChangeType(HandleType newType) {
107 m_objectTracker[m_type]--;
108 m_type = newType;
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) {
119 if (!hObject)
120 return false;
122 if (hObject == INVALID_HANDLE_VALUE || hObject == (HANDLE)-1)
123 return true;
125 bool bDelete = false;
127 std::unique_lock<CCriticalSection> lock((*hObject->m_internalLock));
128 if (--hObject->m_nRefCount == 0)
129 bDelete = true;
132 if (bDelete)
133 delete hObject;
135 return true;