You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2019/07/30 01:45:19 UTC

[mesos] 01/03: Updated PushGauge to work with double.

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

bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit db864ff4579371a7b7086f3789093ba27bb62279
Author: Benjamin Mahler <bm...@apache.org>
AuthorDate: Mon Jul 29 17:38:11 2019 -0400

    Updated PushGauge to work with double.
    
    This enables adoption in Mesos code, since many PullGauges are
    set with double values.
    
    Review: https://reviews.apache.org/r/71187
---
 .../include/process/metrics/push_gauge.hpp         | 30 +++++++++++++++++-----
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/3rdparty/libprocess/include/process/metrics/push_gauge.hpp b/3rdparty/libprocess/include/process/metrics/push_gauge.hpp
index 0dd2c20..bce1917 100644
--- a/3rdparty/libprocess/include/process/metrics/push_gauge.hpp
+++ b/3rdparty/libprocess/include/process/metrics/push_gauge.hpp
@@ -58,7 +58,7 @@ public:
     return static_cast<double>(data->value.load());
   }
 
-  PushGauge& operator=(int64_t v)
+  PushGauge& operator=(double v)
   {
     data->value.store(v);
     push(v);
@@ -67,18 +67,36 @@ public:
 
   PushGauge& operator++() { return *this += 1; }
 
-  PushGauge& operator+=(int64_t v)
+  PushGauge& operator+=(double v)
   {
-    int64_t prev = data->value.fetch_add(v);
+    double prev;
+
+    while (true) {
+      prev = data->value.load();
+
+      if (data->value.compare_exchange_weak(prev, prev + v)) {
+        break;
+      }
+    }
+
     push(static_cast<double>(prev + v));
     return *this;
   }
 
   PushGauge& operator--() { return *this -= 1; }
 
-  PushGauge& operator-=(int64_t v)
+  PushGauge& operator-=(double v)
   {
-    int64_t prev = data->value.fetch_sub(v);
+    double prev;
+
+    while (true) {
+      prev = data->value.load();
+
+      if (data->value.compare_exchange_weak(prev, prev - v)) {
+        break;
+      }
+    }
+
     push(static_cast<double>(prev - v));
     return *this;
   }
@@ -88,7 +106,7 @@ private:
   {
     explicit Data() : value(0) {}
 
-    std::atomic<int64_t> value;
+    std::atomic<double> value;
   };
 
   std::shared_ptr<Data> data;