From f602bfa6c907ec63bc69070f275e7370ab0dd0f4 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 6 Dec 2014 01:10:27 +0100 Subject: [PATCH] Re-implemented reference counting for JobObject. --- LameXP_VS2013.sln | 3 +++ src/Config.h | 2 +- src/Tool_Abstract.cpp | 16 ++++++++++++---- src/Tool_Abstract.h | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/LameXP_VS2013.sln b/LameXP_VS2013.sln index 4ebe063c..da57aa1f 100644 --- a/LameXP_VS2013.sln +++ b/LameXP_VS2013.sln @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LameXP", "LameXP_VS2013.vcxproj", "{00FE736A-8DB1-41B3-B915-4CD8DB09EF48}" + ProjectSection(ProjectDependencies) = postProject + {55405FE1-149F-434C-9D72-4B64348D2A08} = {55405FE1-149F-434C-9D72-4B64348D2A08} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MUtilities", "..\MUtilities\MUtilities_VS2013.vcxproj", "{55405FE1-149F-434C-9D72-4B64348D2A08}" EndProject diff --git a/src/Config.h b/src/Config.h index 8dfa8619..4665ffcd 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,7 +35,7 @@ #define VER_LAMEXP_MINOR_LO 1 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 5 -#define VER_LAMEXP_BUILD 1616 +#define VER_LAMEXP_BUILD 1617 #define VER_LAMEXP_CONFG 1558 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index a68d629b..f8549046 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -43,6 +43,7 @@ */ QScopedPointer AbstractTool::s_jobObject; QMutex AbstractTool::s_jobObjMtx; +quint64 AbstractTool::s_jobObjCnt = 0ui64; /* * Process Timer @@ -60,15 +61,16 @@ static const quint64 START_DELAY_NANO = quint64(START_DELAY) * 10000ui64; //in 1 * Constructor */ AbstractTool::AbstractTool(void) +: + m_firstLaunch(true) + { QMutexLocker lock(&s_jobObjMtx); - if(s_jobObject.isNull()) + if(s_jobObjCnt++ == 0) { s_jobObject.reset(new JobObject()); } - - m_firstLaunch = true; } /* @@ -76,6 +78,12 @@ AbstractTool::AbstractTool(void) */ AbstractTool::~AbstractTool(void) { + QMutexLocker lock(&s_jobObjMtx); + + if(--s_jobObjCnt == 0) + { + s_jobObject.reset(NULL); + } } /* @@ -102,7 +110,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const if(process.waitForStarted()) { - if(s_jobObject) + if(!s_jobObject.isNull()) { if(!s_jobObject->addProcessToJob(&process)) { diff --git a/src/Tool_Abstract.h b/src/Tool_Abstract.h index 06725576..c311f187 100644 --- a/src/Tool_Abstract.h +++ b/src/Tool_Abstract.h @@ -52,6 +52,7 @@ private: static QScopedPointer s_jobObject; static QMutex s_jobObjMtx; + static quint64 s_jobObjCnt; bool m_firstLaunch; };