diff --git a/src/Config.h b/src/Config.h index 4665ffcd..a52c269a 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 1617 +#define VER_LAMEXP_BUILD 1619 #define VER_LAMEXP_CONFG 1558 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index b8482d40..bc36406b 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,6 @@ AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstSta m_disque(NULL), m_disqueTimer(NULL), m_rotateNext(false), - m_disqueDelay(_I64_MAX), m_lastTab(0) { //Init the dialog, from the .ui file @@ -387,17 +387,18 @@ void AboutDialog::gotoLicenseTab(void) void AboutDialog::moveDisque(void) { int delta = 2; - const qint64 perfFrequ = MUtils::OS::perfcounter_freq(); - const qint64 perfCount = MUtils::OS::perfcounter_read(); + QElapsedTimer elapsedTimer; + elapsedTimer.start(); - if((perfFrequ >= 0) && (perfCount >= 0)) + if((!m_disqueDelay.isNull()) && m_disqueDelay->isValid()) { - if(m_disqueDelay != _I64_MAX) - { - const double delay = static_cast(perfCount) - static_cast(m_disqueDelay); - delta = qMax(1, qMin(128, static_cast(ceil(delay / static_cast(perfFrequ) / 0.00512)))); - } - m_disqueDelay = perfCount; + const qint64 delay = m_disqueDelay->restart(); + delta = qBound(1, static_cast(ceil(static_cast(delay) / 5.12)), 128); + } + else + { + m_disqueDelay.reset(new QElapsedTimer()); + m_disqueDelay->start(); } if(m_disque) diff --git a/src/Dialog_About.h b/src/Dialog_About.h index b9bd42f9..a486a760 100644 --- a/src/Dialog_About.h +++ b/src/Dialog_About.h @@ -33,6 +33,7 @@ namespace Ui { class QLabel; class QPixmap; class QTimer; +class QElapsedTimer; class SettingsModel; //AboutDialog class @@ -78,7 +79,7 @@ private: double m_discOpacity; QPixmap *m_cartoon[4]; bool m_rotateNext; - __int64 m_disqueDelay; + QScopedPointer m_disqueDelay; void initInformationTab(void); void initContributorsTab(void); diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 2a66e4e1..3f7f6fca 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -69,10 +69,12 @@ #include #include #include +#include #include #include #include +#include //////////////////////////////////////////////////////////// @@ -291,7 +293,6 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, const AudioFile m_skippedJobs.clear(); m_userAborted = false; m_forcedAbort = false; - m_timerStart = 0I64; } //////////////////////////////////////////////////////////// @@ -555,7 +556,9 @@ void ProcessingDialog::initEncoding(void) m_initThreads = m_threadPool->maxThreadCount(); QTimer::singleShot(100, this, SLOT(initNextJob())); - m_timerStart = MUtils::OS::perfcounter_read(); + + m_totalTime.reset(new QElapsedTimer()); + m_totalTime->start(); } void ProcessingDialog::initNextJob(void) @@ -705,15 +708,10 @@ void ProcessingDialog::doneEncoding(void) } else { - const qint64 counter = MUtils::OS::perfcounter_read(); - const qint64 frequency = MUtils::OS::perfcounter_freq(); - if((counter >= 0I64) && (frequency >= 0)) + if((!m_totalTime.isNull()) && m_totalTime->isValid()) { - if((m_timerStart >= 0I64) && (m_timerStart < counter)) - { - double timeElapsed = static_cast(counter - m_timerStart) / static_cast(frequency); - m_progressModel->addSystemMessage(tr("Process finished after %1.").arg(time2text(timeElapsed)), ProgressModel::SysMsg_Performance); - } + m_progressModel->addSystemMessage(tr("Process finished after %1.").arg(time2text(m_totalTime->elapsed())), ProgressModel::SysMsg_Performance); + m_totalTime->invalidate(); } if(m_failedJobs.count() > 0) @@ -1151,18 +1149,16 @@ bool ProcessingDialog::shutdownComputer(void) return true; } -QString ProcessingDialog::time2text(const double timeVal) const +QString ProcessingDialog::time2text(const qint64 &msec) const { - double intPart = 0; - double frcPart = modf(timeVal, &intPart); - - QTime time = QTime().addSecs(qRound(intPart)).addMSecs(qRound(frcPart * 1000.0)); + const qint64 MILLISECONDS_PER_DAY = 86399999; //24x60x60x1000 - 1 + const QTime time = QTime().addMSecs(qMin(msec, MILLISECONDS_PER_DAY)); QString a, b; if(time.hour() > 0) { - a = tr("%n hour(s)", "", time.hour()); + a = tr("%n hour(s)", "", time.hour()); b = tr("%n minute(s)", "", time.minute()); } else if(time.minute() > 0) @@ -1172,7 +1168,7 @@ QString ProcessingDialog::time2text(const double timeVal) const } else { - a = tr("%n second(s)", "", time.second()); + a = tr("%n second(s)", "", time.second()); b = tr("%n millisecond(s)", "", time.msec()); } diff --git a/src/Dialog_Processing.h b/src/Dialog_Processing.h index 3cee9c01..b8edf239 100644 --- a/src/Dialog_Processing.h +++ b/src/Dialog_Processing.h @@ -40,10 +40,10 @@ class QLabel; class QMenu; class QModelIndex; class QMovie; +class QThreadPool; +class QElapsedTimer; class RAMObserverThread; class SettingsModel; -class QThreadPool; -class lamexp_icon_t; enum shutdownFlag_t { @@ -105,7 +105,7 @@ private: AudioFileModel updateMetaInfo(AudioFileModel &audioFile); void writePlayList(void); bool shutdownComputer(void); - QString time2text(const double timeVal) const; + QString time2text(const qint64 &msec) const; QThreadPool *m_threadPool; QList m_pendingJobs; @@ -133,7 +133,7 @@ private: CPUObserverThread *m_cpuObserver; RAMObserverThread *m_ramObserver; DiskObserverThread *m_diskObserver; - qint64 m_timerStart; + QScopedPointer m_totalTime; int m_progressViewFilter; QColor *m_defaultColor; }; diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index b2021303..16cde2cb 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -44,6 +44,7 @@ #include #include #include +#include /* helper macros */ #define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X) @@ -319,7 +320,9 @@ double InitializationThread::doInit(const size_t threadCount) LockedFile::selfTest(); ExtractorTask::clearFlags(); - const long long timeExtractStart = MUtils::OS::perfcounter_read(); + //Start the timer + QElapsedTimer timeExtractStart; + timeExtractStart.start(); //Extract all files while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty())) @@ -364,7 +367,9 @@ double InitializationThread::doInit(const size_t threadCount) pool->waitForDone(); MUTILS_DELETE(pool); - const long long timeExtractEnd = MUtils::OS::perfcounter_read(); + //Performance measure + const qint64 delayExtract = timeExtractStart.elapsed(); + timeExtractStart.invalidate(); //Make sure all files were extracted correctly if(ExtractorTask::getExcept()) @@ -388,8 +393,7 @@ double InitializationThread::doInit(const size_t threadCount) } //Check delay - const double delayExtract = static_cast(timeExtractEnd - timeExtractStart) / static_cast(MUtils::OS::perfcounter_freq()); - if(delayExtract > g_allowedExtractDelay) + if((double(delayExtract) / 1000.0) > g_allowedExtractDelay) { m_slowIndicator = true; qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract); diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index f8549046..b4f3534a 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -37,25 +37,29 @@ #include #include #include +#include /* - * Job Object + * Static Objects */ -QScopedPointer AbstractTool::s_jobObject; -QMutex AbstractTool::s_jobObjMtx; -quint64 AbstractTool::s_jobObjCnt = 0ui64; +QScopedPointer AbstractTool::s_jobObjectInstance; +QScopedPointer AbstractTool::s_startProcessTimer; /* - * Process Timer + * Synchronization */ -quint64 AbstractTool::s_startProcessTimer = 0ui64; -QMutex AbstractTool::s_startProcessMutex; +QMutex AbstractTool::s_startProcessMutex; +QMutex AbstractTool::s_createObjectMutex; + +/* + * Ref Counter + */ +quint64 AbstractTool::s_referenceCounter = 0ui64; /* * Const */ -static const unsigned int START_DELAY = 100U; //in milliseconds -static const quint64 START_DELAY_NANO = quint64(START_DELAY) * 10000ui64; //in 100-nanosecond intervals +static const qint64 START_DELAY = 64i64; //in milliseconds /* * Constructor @@ -65,11 +69,12 @@ AbstractTool::AbstractTool(void) m_firstLaunch(true) { - QMutexLocker lock(&s_jobObjMtx); + QMutexLocker lock(&s_createObjectMutex); - if(s_jobObjCnt++ == 0) + if(s_referenceCounter++ == 0) { - s_jobObject.reset(new JobObject()); + s_jobObjectInstance.reset(new JobObject()); + s_startProcessTimer.reset(new QElapsedTimer()); } } @@ -78,11 +83,12 @@ AbstractTool::AbstractTool(void) */ AbstractTool::~AbstractTool(void) { - QMutexLocker lock(&s_jobObjMtx); + QMutexLocker lock(&s_createObjectMutex); - if(--s_jobObjCnt == 0) + if(--s_referenceCounter == 0) { - s_jobObject.reset(NULL); + s_jobObjectInstance.reset(NULL); + s_startProcessTimer.reset(NULL); } } @@ -93,14 +99,16 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const { QMutexLocker lock(&s_startProcessMutex); - quint64 currentFileTime = MUtils::OS::current_file_time(); - while(currentFileTime < s_startProcessTimer) + if((!s_startProcessTimer.isNull()) && s_startProcessTimer->isValid()) { - const quint64 expectedFileTime = s_startProcessTimer; - lock.unlock(); - MUtils::OS::sleep_ms(size_t((expectedFileTime - currentFileTime) / 10000ui64) + 1U); - lock.relock(); - currentFileTime = MUtils::OS::current_file_time(); + qint64 elapsed = s_startProcessTimer->elapsed(); + while(elapsed < START_DELAY) + { + lock.unlock(); + MUtils::OS::sleep_ms((size_t)(START_DELAY - elapsed)); + lock.relock(); + elapsed = s_startProcessTimer->elapsed(); + } } emit messageLogged(commandline2string(program, args) + "\n"); @@ -110,9 +118,9 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const if(process.waitForStarted()) { - if(!s_jobObject.isNull()) + if(!s_jobObjectInstance.isNull()) { - if(!s_jobObject->addProcessToJob(&process)) + if(!s_jobObjectInstance->addProcessToJob(&process)) { qWarning("Failed to assign process to job object!"); } @@ -126,7 +134,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const m_firstLaunch = false; } - s_startProcessTimer = MUtils::OS::current_file_time() + START_DELAY_NANO; + s_startProcessTimer->start(); return true; } @@ -137,7 +145,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const process.kill(); process.waitForFinished(-1); - s_startProcessTimer = MUtils::OS::current_file_time() + START_DELAY_NANO; + s_startProcessTimer->start(); return false; } diff --git a/src/Tool_Abstract.h b/src/Tool_Abstract.h index c311f187..d54b413e 100644 --- a/src/Tool_Abstract.h +++ b/src/Tool_Abstract.h @@ -26,6 +26,7 @@ class QMutex; class QProcess; +class QElapsedTimer; class JobObject; class AbstractTool : public QObject @@ -47,12 +48,13 @@ protected: static const int m_processTimeoutInterval = 600000; private: - static quint64 s_startProcessTimer; - static QMutex s_startProcessMutex; + static QScopedPointer s_jobObjectInstance; + static QScopedPointer s_startProcessTimer; - static QScopedPointer s_jobObject; - static QMutex s_jobObjMtx; - static quint64 s_jobObjCnt; + static QMutex s_startProcessMutex; + static QMutex s_createObjectMutex; + + static quint64 s_referenceCounter; bool m_firstLaunch; };