]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#891,!592] remove mutex from StatContext as all functions are called in a thread...
authorRazvan Becheriu <razvan@isc.org>
Mon, 18 Nov 2019 10:48:02 +0000 (12:48 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 5 Feb 2020 19:57:37 +0000 (21:57 +0200)
src/lib/stats/context.cc
src/lib/stats/context.h

index 1c86a37367000c4f2d7000030c446047de117731..13c82ca409fc1e8d01517b6ab7295ecbb54bfdd6 100644 (file)
@@ -18,10 +18,6 @@ namespace isc {
 namespace stats {
 
 ObservationPtr StatContext::get(const std::string& name) const {
-    return MultiThreadingMgr::call(mutex_, [&]() {return getInternal(name);});
-}
-
-ObservationPtr StatContext::getInternal(const std::string& name) const {
     auto obs = stats_.find(name);
     if (obs != stats_.end()) {
         return (obs->second);
@@ -30,10 +26,6 @@ ObservationPtr StatContext::getInternal(const std::string& name) const {
 }
 
 void StatContext::add(const ObservationPtr& obs) {
-    MultiThreadingMgr::call(mutex_, [&]() {addInternal(obs);});
-}
-
-void StatContext::addInternal(const ObservationPtr& obs) {
     auto existing = stats_.find(obs->getName());
     if (existing == stats_.end()) {
         stats_.insert(make_pair(obs->getName() ,obs));
@@ -44,10 +36,6 @@ void StatContext::addInternal(const ObservationPtr& obs) {
 }
 
 bool StatContext::del(const std::string& name) {
-    return (MultiThreadingMgr::call(mutex_, [&]() {return delInternal(name);}));
-}
-
-bool StatContext::delInternal(const std::string& name) {
     auto obs = stats_.find(name);
     if (obs != stats_.end()) {
         stats_.erase(obs);
@@ -57,26 +45,14 @@ bool StatContext::delInternal(const std::string& name) {
 }
 
 size_t StatContext::size() {
-    return (MultiThreadingMgr::call(mutex_, [&]() {return sizeInternal();}));
-}
-
-size_t StatContext::sizeInternal() {
     return (stats_.size());
 }
 
 void StatContext::clear() {
-    MultiThreadingMgr::call(mutex_, [&]() {clearInternal();});
-}
-
-void StatContext::clearInternal() {
     stats_.clear();
 }
 
 void StatContext::resetAll() {
-    MultiThreadingMgr::call(mutex_, [&]() {resetAllInternal();});
-}
-
-void StatContext::resetAllInternal() {
     // Let's iterate over all stored statistics...
     for (auto s : stats_) {
         // ... and reset each statistic.
@@ -85,10 +61,6 @@ void StatContext::resetAllInternal() {
 }
 
 ConstElementPtr StatContext::getAll() const {
-    return (MultiThreadingMgr::call(mutex_, [&]() {return getAllInternal();}));
-}
-
-ConstElementPtr StatContext::getAllInternal() const {
     ElementPtr map = Element::createMap(); // a map
     // Let's iterate over all stored statistics...
     for (auto s : stats_) {
@@ -99,10 +71,6 @@ ConstElementPtr StatContext::getAllInternal() const {
 }
 
 void StatContext::setMaxSampleCountAll(uint32_t max_samples) {
-    MultiThreadingMgr::call(mutex_, [&]() {setMaxSampleCountAllInternal(max_samples);});
-}
-
-void StatContext::setMaxSampleCountAllInternal(uint32_t max_samples) {
     // Let's iterate over all stored statistics...
     for (auto s : stats_) {
         // ... and set count limit for each statistic.
@@ -111,10 +79,6 @@ void StatContext::setMaxSampleCountAllInternal(uint32_t max_samples) {
 }
 
 void StatContext::setMaxSampleAgeAll(const StatsDuration& duration) {
-    MultiThreadingMgr::call(mutex_, [&]() {setMaxSampleAgeAllInternal(duration);});
-}
-
-void StatContext::setMaxSampleAgeAllInternal(const StatsDuration& duration) {
     // Let's iterate over all stored statistics...
     for (auto s : stats_) {
         // ... and set duration limit for each statistic.
index c64d7c803af347e5f341b587c193041105022b00..e7b6dc247db58f727375d36bd8e06f5ed62a47fa 100644 (file)
@@ -77,55 +77,8 @@ public:
 
 private:
 
-    /// @brief Attempts to get an observation
-    ///
-    /// @param name name of the statistic
-    /// @return appropriate Observation object (or NULL)
-    ObservationPtr getInternal(const std::string& name) const;
-
-    /// @brief Adds a new observation
-    ///
-    /// @param obs observation to be added
-    /// @throw DuplicateStat if an observation with the same name exists already
-    void addInternal(const ObservationPtr& obs);
-
-    /// @brief Attempts to delete an observation
-    ///
-    /// @param name name of the observation to be deleted
-    /// @return true if successful, false if no such statistic was found
-    bool delInternal(const std::string& name);
-
-    /// @brief Returns the number of observations
-    ///
-    /// @return the number of observations
-    size_t sizeInternal();
-
-    /// @brief Removes all observations
-    void clearInternal();
-
-    /// @brief Resets all observations
-    void resetAllInternal();
-
-    /// @brief Sets max sample count for all observations
-    ///
-    /// @param max_samples value to be set for all observations
-    void setMaxSampleCountAllInternal(uint32_t max_samples);
-
-    /// @brief Sets duration for all observations
-    ///
-    /// @param duration value to be set for all observations
-    void setMaxSampleAgeAllInternal(const StatsDuration& duration);
-
-    /// @brief Returns a map with all observations
-    ///
-    /// @return map with all observations
-    isc::data::ConstElementPtr getAllInternal() const;
-
     /// @brief Statistics container
     std::map<std::string, ObservationPtr> stats_;
-
-    /// @brief Mutex used to protect internal state
-    mutable std::mutex mutex_;
 };
 
 /// @brief Pointer to the statistics context