summaryrefslogtreecommitdiffstats
path: root/src/modules/SystemBackendProc
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-03 20:16:23 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-03 20:16:23 +0200
commitfca6c1a831393e173706a5b5c798c35dc5f7d3e6 (patch)
tree38b4b6f59a10736e869eaf460020bf28b4bc8c3d /src/modules/SystemBackendProc
parent23d4cc1dfa5602c266f2f3d71f845f9ef0789b89 (diff)
downloadmad-fca6c1a831393e173706a5b5c798c35dc5f7d3e6.tar
mad-fca6c1a831393e173706a5b5c798c35dc5f7d3e6.zip
Thread-Sicherheit verbessert
Diffstat (limited to 'src/modules/SystemBackendProc')
-rw-r--r--src/modules/SystemBackendProc/SystemBackendProc.cpp8
-rw-r--r--src/modules/SystemBackendProc/SystemBackendProc.h4
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;