diff options
author | deva <deva> | 2010-01-06 08:50:13 +0000 |
---|---|---|
committer | deva <deva> | 2010-01-06 08:50:13 +0000 |
commit | 91988574b7b8d3ccdf186daee9a0f9c33b3803bb (patch) | |
tree | 77628545d616be4b4a7bf23ec8f175cfe483e5f2 | |
parent | 0e819eb42b4d680a99ae7b04702bfc9510495aee (diff) |
Made MacroList and TemplateList threadsafe.
-rw-r--r-- | server/src/macrolist.cc | 5 | ||||
-rw-r--r-- | server/src/macrolist.h | 2 | ||||
-rw-r--r-- | server/src/templatelist.cc | 4 | ||||
-rw-r--r-- | server/src/templatelist.h | 3 |
4 files changed, 14 insertions, 0 deletions
diff --git a/server/src/macrolist.cc b/server/src/macrolist.cc index b67f239..0d0916d 100644 --- a/server/src/macrolist.cc +++ b/server/src/macrolist.cc @@ -58,6 +58,8 @@ static std::vector<std::string> listdir(std::string path) MacroList::MacroList(std::string macropath) { + MutexAutolock lock(mutex); + this->macropath = macropath; std::vector<std::string> macros = listdir(macropath); std::vector<std::string>::iterator i = macros.begin(); @@ -91,6 +93,8 @@ MacroList::MacroList(std::string macropath) std::string MacroList::getLatestVersion(std::string macro) throw(Exception) { + MutexAutolock lock(mutex); + if(find(macro) == end()) throw Exception("Macro ["+macro+"] does not exist"); MacroListItem mli = (*this)[macro]; if(mli.size() == 0) return ""; @@ -98,6 +102,7 @@ std::string MacroList::getLatestVersion(std::string macro) throw(Exception) macro.c_str(), (macropath + "/" + mli.begin()->second).c_str(), ((std::string)mli.begin()->first).c_str()); + return macropath + "/" + mli.begin()->second; } diff --git a/server/src/macrolist.h b/server/src/macrolist.h index 9b9b0d2..6460f8b 100644 --- a/server/src/macrolist.h +++ b/server/src/macrolist.h @@ -31,6 +31,7 @@ #include <map> #include <string> #include "versionstr.h" +#include "mutex.h" #include "exception.h" @@ -66,6 +67,7 @@ public: std::string getLatestVersion(std::string macro) throw(Exception); private: + Mutex mutex; std::string macropath; }; diff --git a/server/src/templatelist.cc b/server/src/templatelist.cc index cdf2b4b..bbaefc3 100644 --- a/server/src/templatelist.cc +++ b/server/src/templatelist.cc @@ -58,6 +58,8 @@ static std::vector<std::string> listdir(std::string path) TemplateList::TemplateList(std::string templatepath) { + MutexAutolock lock(mutex); + this->templatepath = templatepath; std::vector<std::string> templates = listdir(templatepath); std::vector<std::string>::iterator i = templates.begin(); @@ -93,6 +95,8 @@ TemplateList::TemplateList(std::string templatepath) std::string TemplateList::getLatestVersion(std::string templ) throw(Exception) { + MutexAutolock lock(mutex); + if(find(templ) == end()) throw Exception("Template ["+templ+"] does not exist"); TemplateListItem mli = (*this)[templ]; if(mli.size() == 0) return ""; diff --git a/server/src/templatelist.h b/server/src/templatelist.h index bcf22f1..a037956 100644 --- a/server/src/templatelist.h +++ b/server/src/templatelist.h @@ -31,6 +31,8 @@ #include <map> #include <string> #include "versionstr.h" +#include "templatelist.h" +#include "mutex.h" #include "exception.h" @@ -66,6 +68,7 @@ public: std::string getLatestVersion(std::string templ) throw(Exception); private: + Mutex mutex; std::string templatepath; }; |