You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by zh...@apache.org on 2022/10/20 11:02:23 UTC

[incubator-pegasus] branch master updated: refactor(metrics): drop template specialization for gauge (#1192)

This is an automated email from the ASF dual-hosted git repository.

zhaoliwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b17b67af refactor(metrics): drop template specialization for gauge (#1192)
0b17b67af is described below

commit 0b17b67af9d5778de68320ce4a19b59eca9e195b
Author: Dan Wang <wa...@apache.org>
AuthorDate: Thu Oct 20 19:02:19 2022 +0800

    refactor(metrics): drop template specialization for gauge (#1192)
---
 src/rdsn/src/utils/metrics.cpp | 10 ----------
 src/rdsn/src/utils/metrics.h   | 22 ++++++++++++----------
 2 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/rdsn/src/utils/metrics.cpp b/src/rdsn/src/utils/metrics.cpp
index 7ad4d53ee..a45462808 100644
--- a/src/rdsn/src/utils/metrics.cpp
+++ b/src/rdsn/src/utils/metrics.cpp
@@ -267,14 +267,4 @@ void percentile_timer::on_timer(const boost::system::error_code &ec)
 #undef TRY_PROCESS_TIMER_CLOSING
 }
 
-template <>
-gauge<int64_t>::gauge(const metric_prototype *prototype) : gauge(prototype, 0)
-{
-}
-
-template <>
-gauge<double>::gauge(const metric_prototype *prototype) : gauge(prototype, 0.0)
-{
-}
-
 } // namespace dsn
diff --git a/src/rdsn/src/utils/metrics.h b/src/rdsn/src/utils/metrics.h
index b5f5551c5..ae92eafb6 100644
--- a/src/rdsn/src/utils/metrics.h
+++ b/src/rdsn/src/utils/metrics.h
@@ -389,32 +389,34 @@ template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::
 class gauge : public metric
 {
 public:
-    T value() const { return _value.load(std::memory_order_relaxed); }
+    using value_type = T;
+
+    value_type value() const { return _value.load(std::memory_order_relaxed); }
 
-    void set(const T &val) { _value.store(val, std::memory_order_relaxed); }
+    void set(const value_type &val) { _value.store(val, std::memory_order_relaxed); }
 
-    template <typename Int = T,
+    template <typename Int = value_type,
               typename = typename std::enable_if<std::is_integral<Int>::value>::type>
     void increment_by(Int x)
     {
         _value.fetch_add(x, std::memory_order_relaxed);
     }
 
-    template <typename Int = T,
+    template <typename Int = value_type,
               typename = typename std::enable_if<std::is_integral<Int>::value>::type>
     void decrement_by(Int x)
     {
         increment_by(-x);
     }
 
-    template <typename Int = T,
+    template <typename Int = value_type,
               typename = typename std::enable_if<std::is_integral<Int>::value>::type>
     void increment()
     {
         increment_by(1);
     }
 
-    template <typename Int = T,
+    template <typename Int = value_type,
               typename = typename std::enable_if<std::is_integral<Int>::value>::type>
     void decrement()
     {
@@ -422,20 +424,20 @@ public:
     }
 
 protected:
-    gauge(const metric_prototype *prototype, const T &initial_val)
+    gauge(const metric_prototype *prototype, const value_type &initial_val)
         : metric(prototype), _value(initial_val)
     {
     }
 
-    gauge(const metric_prototype *prototype);
+    gauge(const metric_prototype *prototype) : gauge(prototype, value_type()) {}
 
     virtual ~gauge() = default;
 
 private:
     friend class metric_entity;
-    friend class ref_ptr<gauge<T>>;
+    friend class ref_ptr<gauge<value_type>>;
 
-    std::atomic<T> _value;
+    std::atomic<value_type> _value;
 
     DISALLOW_COPY_AND_ASSIGN(gauge);
 };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org