From cafbe44dde55e57115cc654610172556dff19bec Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 24 Apr 2017 19:16:36 -0700 Subject: Controller optimizations -- make locking more fine-grained, use true hardware concurrency, etc. --- controller/JSONDB.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'controller/JSONDB.hpp') diff --git a/controller/JSONDB.hpp b/controller/JSONDB.hpp index beafbaf5..2d3a5224 100644 --- a/controller/JSONDB.hpp +++ b/controller/JSONDB.hpp @@ -51,18 +51,16 @@ public: bool writeRaw(const std::string &n,const std::string &obj); bool put(const std::string &n,const nlohmann::json &obj); - inline bool put(const std::string &n1,const std::string &n2,const nlohmann::json &obj) { return this->put((n1 + "/" + n2),obj); } inline bool put(const std::string &n1,const std::string &n2,const std::string &n3,const nlohmann::json &obj) { return this->put((n1 + "/" + n2 + "/" + n3),obj); } inline bool put(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const nlohmann::json &obj) { return this->put((n1 + "/" + n2 + "/" + n3 + "/" + n4),obj); } inline bool put(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const std::string &n5,const nlohmann::json &obj) { return this->put((n1 + "/" + n2 + "/" + n3 + "/" + n4 + "/" + n5),obj); } - const nlohmann::json &get(const std::string &n); - - inline const nlohmann::json &get(const std::string &n1,const std::string &n2) { return this->get((n1 + "/" + n2)); } - inline const nlohmann::json &get(const std::string &n1,const std::string &n2,const std::string &n3) { return this->get((n1 + "/" + n2 + "/" + n3)); } - inline const nlohmann::json &get(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4) { return this->get((n1 + "/" + n2 + "/" + n3 + "/" + n4)); } - inline const nlohmann::json &get(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const std::string &n5) { return this->get((n1 + "/" + n2 + "/" + n3 + "/" + n4 + "/" + n5)); } + nlohmann::json get(const std::string &n); + inline nlohmann::json get(const std::string &n1,const std::string &n2) { return this->get((n1 + "/" + n2)); } + inline nlohmann::json get(const std::string &n1,const std::string &n2,const std::string &n3) { return this->get((n1 + "/" + n2 + "/" + n3)); } + inline nlohmann::json get(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4) { return this->get((n1 + "/" + n2 + "/" + n3 + "/" + n4)); } + inline nlohmann::json get(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const std::string &n5) { return this->get((n1 + "/" + n2 + "/" + n3 + "/" + n4 + "/" + n5)); } void erase(const std::string &n); @@ -74,6 +72,8 @@ public: template inline void filter(const std::string &prefix,F func) { + Mutex::Lock _l(_db_m); + while (!_ready) { Thread::sleep(250); _ready = _reload(_basePath,std::string()); @@ -108,6 +108,7 @@ private: InetAddress _httpAddr; std::string _basePath; std::map _db; + Mutex _db_m; volatile bool _ready; }; -- cgit v1.2.3