From 91988574b7b8d3ccdf186daee9a0f9c33b3803bb Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 6 Jan 2010 08:50:13 +0000 Subject: Made MacroList and TemplateList threadsafe. --- server/src/macrolist.cc | 5 +++++ server/src/macrolist.h | 2 ++ server/src/templatelist.cc | 4 ++++ server/src/templatelist.h | 3 +++ 4 files changed, 14 insertions(+) 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 listdir(std::string path) MacroList::MacroList(std::string macropath) { + MutexAutolock lock(mutex); + this->macropath = macropath; std::vector macros = listdir(macropath); std::vector::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 #include #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 listdir(std::string path) TemplateList::TemplateList(std::string templatepath) { + MutexAutolock lock(mutex); + this->templatepath = templatepath; std::vector templates = listdir(templatepath); std::vector::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 #include #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; }; -- cgit v1.2.3