2011-10-29 16:26:09 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2016-01-03 15:53:42 +01:00
|
|
|
// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
|
2011-10-29 16:26:09 +02:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2011-10-29 16:26:09 +02:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Thread_RAMObserver.h"
|
|
|
|
#include "Global.h"
|
|
|
|
|
2014-11-25 18:23:03 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/OSSupport.h>
|
2014-11-30 21:32:23 +01:00
|
|
|
#include <MUtils/Exception.h>
|
2014-11-25 18:23:03 +01:00
|
|
|
|
|
|
|
//Qt
|
2011-10-29 16:26:09 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
2013-10-06 19:28:12 +02:00
|
|
|
//Windows includes
|
|
|
|
#define NOMINMAX
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
|
2011-10-29 16:26:09 +02:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor & Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
RAMObserverThread::RAMObserverThread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RAMObserverThread::~RAMObserverThread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Protected functions
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void RAMObserverThread::run(void)
|
|
|
|
{
|
|
|
|
qDebug("RAM observer started!");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
observe();
|
|
|
|
}
|
2013-10-18 21:37:40 +02:00
|
|
|
catch(const std::exception &error)
|
|
|
|
{
|
2014-11-30 21:32:23 +01:00
|
|
|
MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
|
2014-11-25 18:23:03 +01:00
|
|
|
MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
|
2013-10-18 21:37:40 +02:00
|
|
|
}
|
2011-10-29 16:26:09 +02:00
|
|
|
catch(...)
|
|
|
|
{
|
2014-11-30 21:32:23 +01:00
|
|
|
MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
|
2014-11-25 18:23:03 +01:00
|
|
|
MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
|
2011-10-29 16:26:09 +02:00
|
|
|
}
|
2011-11-25 01:01:30 +01:00
|
|
|
|
|
|
|
while(m_semaphore.available()) m_semaphore.tryAcquire();
|
2011-10-29 16:26:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RAMObserverThread::observe(void)
|
|
|
|
{
|
|
|
|
MEMORYSTATUSEX memoryStatus;
|
|
|
|
double previous = -1.0;
|
|
|
|
|
2011-11-25 01:01:30 +01:00
|
|
|
forever
|
2011-10-29 16:26:09 +02:00
|
|
|
{
|
|
|
|
memset(&memoryStatus, 0, sizeof(MEMORYSTATUSEX));
|
|
|
|
memoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
|
|
|
|
|
|
|
|
if(GlobalMemoryStatusEx(&memoryStatus))
|
|
|
|
{
|
|
|
|
double current = static_cast<double>(memoryStatus.dwMemoryLoad) / 100.0;
|
|
|
|
if(current != previous)
|
|
|
|
{
|
|
|
|
emit currentUsageChanged(current);
|
|
|
|
previous = current;
|
|
|
|
}
|
|
|
|
}
|
2011-11-25 01:01:30 +01:00
|
|
|
if(m_semaphore.tryAcquire(1, 2000)) break;
|
2011-10-29 16:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// SLOTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*NONE*/
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*NONE*/
|