summaryrefslogtreecommitdiff
path: root/controller/DB.hpp
diff options
context:
space:
mode:
authorGrant Limberg <[email protected]>2023-05-23 12:11:26 -0700
committerGitHub <[email protected]>2023-05-23 12:11:26 -0700
commit17f6b3a10b1f1b3bc18c950f762d87fd64a8ce09 (patch)
tree88b6cfd31b4c41cdd0feb41b783862e7f2c5f753 /controller/DB.hpp
parentda71e2524c343f563ea9c37e9668eec7c5719aaa (diff)
central controller metrics & request path updates (#2012)
* internal db metrics * use shared mutexes for read/write locks * remove this lock. only used for a metric * more metrics * remove exploratory metrics place controller request benchmarks behind ifdef
Diffstat (limited to 'controller/DB.hpp')
-rw-r--r--controller/DB.hpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/controller/DB.hpp b/controller/DB.hpp
index f70d66e0..89610f7c 100644
--- a/controller/DB.hpp
+++ b/controller/DB.hpp
@@ -29,7 +29,7 @@
#include <unordered_set>
#include <vector>
#include <atomic>
-#include <mutex>
+#include <shared_mutex>
#include <set>
#include <map>
@@ -109,7 +109,7 @@ public:
inline bool hasNetwork(const uint64_t networkId) const
{
- std::lock_guard<std::mutex> l(_networks_l);
+ std::shared_lock<std::shared_mutex> l(_networks_l);
return (_networks.find(networkId) != _networks.end());
}
@@ -124,7 +124,7 @@ public:
inline void each(F f)
{
nlohmann::json nullJson;
- std::lock_guard<std::mutex> lck(_networks_l);
+ std::unique_lock<std::shared_mutex> lck(_networks_l);
for(auto nw=_networks.begin();nw!=_networks.end();++nw) {
f(nw->first,nw->second->config,0,nullJson); // first provide network with 0 for member ID
for(auto m=nw->second->members.begin();m!=nw->second->members.end();++m) {
@@ -142,7 +142,7 @@ public:
inline void addListener(DB::ChangeListener *const listener)
{
- std::lock_guard<std::mutex> l(_changeListeners_l);
+ std::unique_lock<std::shared_mutex> l(_changeListeners_l);
_changeListeners.push_back(listener);
}
@@ -178,7 +178,7 @@ protected:
std::unordered_set<uint64_t> authorizedMembers;
std::unordered_set<InetAddress,InetAddress::Hasher> allocatedIps;
int64_t mostRecentDeauthTime;
- std::mutex lock;
+ std::shared_mutex lock;
};
virtual void _memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool notifyListeners);
@@ -188,8 +188,8 @@ protected:
std::vector<DB::ChangeListener *> _changeListeners;
std::unordered_map< uint64_t,std::shared_ptr<_Network> > _networks;
std::unordered_multimap< uint64_t,uint64_t > _networkByMember;
- mutable std::mutex _changeListeners_l;
- mutable std::mutex _networks_l;
+ mutable std::shared_mutex _changeListeners_l;
+ mutable std::shared_mutex _networks_l;
};
} // namespace ZeroTier