From fca6c1a831393e173706a5b5c798c35dc5f7d3e6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 3 Sep 2009 20:16:23 +0200 Subject: Thread-Sicherheit verbessert --- src/modules/SystemBackendProc/SystemBackendProc.cpp | 8 ++++++++ src/modules/SystemBackendProc/SystemBackendProc.h | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'src/modules/SystemBackendProc') 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 +#include + #include #include @@ -31,6 +33,8 @@ namespace SystemBackendProc { void SystemBackendProc::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception) { application->getThreadManager()->detach(); + boost::lock_guard 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 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 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 #include +#include + #include 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; -- cgit v1.2.3