diff options
Diffstat (limited to 'src/modules/SystemBackendProc')
-rw-r--r-- | src/modules/SystemBackendProc/SystemBackendProc.cpp | 8 | ||||
-rw-r--r-- | src/modules/SystemBackendProc/SystemBackendProc.h | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/modules/SystemBackendProc/SystemBackendProc.cpp b/src/modules/SystemBackendProc/SystemBackendProc.cpp index fb4d4e4..1a8c9c4 100644 --- a/src/modules/SystemBackendProc/SystemBackendProc.cpp +++ b/src/modules/SystemBackendProc/SystemBackendProc.cpp @@ -21,6 +21,8 @@ #include <Core/ThreadManager.h> +#include <boost/thread/locks.hpp> + #include <cstdio> #include <cstring> @@ -31,6 +33,8 @@ namespace SystemBackendProc { void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception) { application->getThreadManager()->detach(); + boost::lock_guard<boost::mutex> lock(uptimeMutex); + uptimeFile.seekg(0, std::ios::beg); if(!uptimeFile.good()) @@ -52,6 +56,8 @@ void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idle void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception) { application->getThreadManager()->detach(); + boost::lock_guard<boost::mutex> lock(meminfoMutex); + if(totalMem) *totalMem = 0; if(freeMem) @@ -94,6 +100,8 @@ void SystemBackendProc::getMemoryInfo(unsigned long *totalMem, unsigned long *fr void SystemBackendProc::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception) { application->getThreadManager()->detach(); + boost::lock_guard<boost::mutex> lock(loadMutex); + unsigned long currentLoadValue = 0, nProcessesValue = 0; float loadAvg1Value = 0, loadAvg5Value = 0, loadAvg15Value = 0; diff --git a/src/modules/SystemBackendProc/SystemBackendProc.h b/src/modules/SystemBackendProc/SystemBackendProc.h index a6a7835..99cc800 100644 --- a/src/modules/SystemBackendProc/SystemBackendProc.h +++ b/src/modules/SystemBackendProc/SystemBackendProc.h @@ -23,6 +23,8 @@ #include <Common/SystemBackend.h> #include <Common/Application.h> +#include <boost/thread/mutex.hpp> + #include <fstream> namespace Mad { @@ -33,6 +35,8 @@ class SystemBackendProc : public Common::SystemBackend { private: Common::Application *application; + boost::mutex uptimeMutex, meminfoMutex, loadMutex; + std::ifstream uptimeFile; std::ifstream meminfoFile; std::ifstream loadFile; |