summaryrefslogtreecommitdiff
path: root/controller/JSONDB.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-24 19:16:36 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-24 19:16:36 -0700
commitcafbe44dde55e57115cc654610172556dff19bec (patch)
tree3e6e22d491535e16e97c94388b7ec02e3b7f0c2a /controller/JSONDB.hpp
parent6234bfd8bf47ad3fc1f5b87adea73c62839f2864 (diff)
downloadinfinitytier-cafbe44dde55e57115cc654610172556dff19bec.tar.gz
infinitytier-cafbe44dde55e57115cc654610172556dff19bec.zip
Controller optimizations -- make locking more fine-grained, use true hardware concurrency, etc.
Diffstat (limited to 'controller/JSONDB.hpp')
-rw-r--r--controller/JSONDB.hpp15
1 files changed, 8 insertions, 7 deletions
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<typename F>
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<std::string,_E> _db;
+ Mutex _db_m;
volatile bool _ready;
};