ConfigFile thread safe.
This commit is contained in:
@@ -232,6 +232,8 @@ ConfigFile::~ConfigFile()
|
||||
|
||||
void ConfigFile::fillBuffer() {
|
||||
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
size_t i;
|
||||
string tempString("");
|
||||
|
||||
@@ -257,7 +259,9 @@ void ConfigFile::fillBuffer() {
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigFile::writeBuffer() {
|
||||
void ConfigFile::writeBuffer() const {
|
||||
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
//write buffer to disc if enabled
|
||||
if(!noWriteAccess) {
|
||||
@@ -286,6 +290,8 @@ void ConfigFile::writeBuffer() {
|
||||
|
||||
void ConfigFile::updateConfig(ConfigState myConfigState) {
|
||||
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
size_t i;
|
||||
|
||||
if(myConfigState == NONEXISTING) {
|
||||
@@ -369,8 +375,10 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
|
||||
}
|
||||
}
|
||||
|
||||
string ConfigFile::readConfigString(string varName)
|
||||
string ConfigFile::readConfigString(string varName) const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
size_t i;
|
||||
string tempString("");
|
||||
|
||||
@@ -404,8 +412,10 @@ string ConfigFile::readConfigString(string varName)
|
||||
return tempString;
|
||||
}
|
||||
|
||||
int ConfigFile::readConfigInt(string varName)
|
||||
int ConfigFile::readConfigInt(string varName) const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
size_t i;
|
||||
string tempString("");
|
||||
int tempInt=0;
|
||||
@@ -449,7 +459,9 @@ int ConfigFile::readConfigInt(string varName)
|
||||
|
||||
|
||||
void ConfigFile::writeConfigInt(string varName, int varCont)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
size_t i;
|
||||
string tempString;
|
||||
ostringstream intToString;
|
||||
@@ -464,7 +476,9 @@ void ConfigFile::writeConfigInt(string varName, int varCont)
|
||||
}
|
||||
|
||||
void ConfigFile::writeConfigString(string varName, string varCont)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_configMutex);
|
||||
|
||||
size_t i;
|
||||
for (i=0; i<configBufferList.size(); i++) {
|
||||
if (configBufferList[i].name == varName) { configBufferList[i].defaultValue = varCont; }
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
enum ConfigState { NONEXISTING, OLD };
|
||||
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING };
|
||||
@@ -38,19 +38,20 @@ public:
|
||||
~ConfigFile();
|
||||
|
||||
void fillBuffer();
|
||||
void writeBuffer();
|
||||
void writeBuffer() const;
|
||||
|
||||
void updateConfig(ConfigState);
|
||||
|
||||
std::string readConfigString(std::string varName);
|
||||
std::string readConfigString(std::string varName) const;
|
||||
void writeConfigString(std::string varName, std::string varCont);
|
||||
|
||||
int readConfigInt(std::string varName);
|
||||
int readConfigInt(std::string varName) const;
|
||||
void writeConfigInt(std::string varName, int varCont);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
mutable boost::mutex m_configMutex;
|
||||
|
||||
struct ConfigInfo
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user