summaryrefslogtreecommitdiff
path: root/controller/JSONDB.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-24 20:51:02 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-24 20:51:02 -0700
commit4f2a77976965f19640416afca24367d3037820b8 (patch)
treee68402e6564180cfe39b1d77ffc51c87120b7dd3 /controller/JSONDB.hpp
parentcafbe44dde55e57115cc654610172556dff19bec (diff)
downloadinfinitytier-4f2a77976965f19640416afca24367d3037820b8.tar.gz
infinitytier-4f2a77976965f19640416afca24367d3037820b8.zip
JSONDB performance improvements, threading fix.
Diffstat (limited to 'controller/JSONDB.hpp')
-rw-r--r--controller/JSONDB.hpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/controller/JSONDB.hpp b/controller/JSONDB.hpp
index 2d3a5224..a045d1b4 100644
--- a/controller/JSONDB.hpp
+++ b/controller/JSONDB.hpp
@@ -72,29 +72,28 @@ 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());
+ _reload(_basePath,std::string());
}
-
- for(std::map<std::string,_E>::iterator i(_db.lower_bound(prefix));i!=_db.end();) {
- if ((i->first.length() >= prefix.length())&&(!memcmp(i->first.data(),prefix.data(),prefix.length()))) {
- if (!func(i->first,get(i->first))) {
- std::map<std::string,_E>::iterator i2(i); ++i2;
- this->erase(i->first);
- i = i2;
- } else ++i;
- } else break;
+ {
+ Mutex::Lock _l(_db_m);
+ for(std::map<std::string,_E>::iterator i(_db.lower_bound(prefix));i!=_db.end();) {
+ if ((i->first.length() >= prefix.length())&&(!memcmp(i->first.data(),prefix.data(),prefix.length()))) {
+ if (!func(i->first,i->second.obj)) {
+ this->_erase(i->first);
+ _db.erase(i++);
+ } else {
+ ++i;
+ }
+ } else break;
+ }
}
}
- inline bool operator==(const JSONDB &db) const { return ((_basePath == db._basePath)&&(_db == db._db)); }
- inline bool operator!=(const JSONDB &db) const { return (!(*this == db)); }
-
private:
- bool _reload(const std::string &p,const std::string &b);
+ void _erase(const std::string &n);
+ void _reload(const std::string &p,const std::string &b);
bool _isValidObjectName(const std::string &n);
std::string _genPath(const std::string &n,bool create);