mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [8/9] mesos git commit: Refactor Metrics::Metric to use synchronized.
Date Thu, 04 Jun 2015 07:30:29 GMT
Refactor Metrics::Metric to use synchronized.

Review: https://reviews.apache.org/r/32363


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8c2d8d47
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8c2d8d47
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8c2d8d47

Branch: refs/heads/master
Commit: 8c2d8d47f2bed2c15a5db2d0dc1afb33025f4af0
Parents: 8323bca
Author: Joris Van Remoortere <joris.van.remoortere@gmail.com>
Authored: Thu Jun 4 00:26:16 2015 -0700
Committer: Benjamin Hindman <benjamin.hindman@gmail.com>
Committed: Thu Jun 4 00:26:16 2015 -0700

----------------------------------------------------------------------
 .../libprocess/include/process/metrics/metric.hpp    | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8c2d8d47/3rdparty/libprocess/include/process/metrics/metric.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/metrics/metric.hpp b/3rdparty/libprocess/include/process/metrics/metric.hpp
index a7be2d7..44a7d5a 100644
--- a/3rdparty/libprocess/include/process/metrics/metric.hpp
+++ b/3rdparty/libprocess/include/process/metrics/metric.hpp
@@ -1,17 +1,18 @@
 #ifndef __PROCESS_METRICS_METRIC_HPP__
 #define __PROCESS_METRICS_METRIC_HPP__
 
+#include <atomic>
 #include <memory>
 #include <string>
 
 #include <process/future.hpp>
-#include <process/internal.hpp>
 #include <process/owned.hpp>
 #include <process/statistics.hpp>
 #include <process/timeseries.hpp>
 
 #include <stout/duration.hpp>
 #include <stout/option.hpp>
+#include <stout/synchronized.hpp>
 
 namespace process {
 namespace metrics {
@@ -33,11 +34,9 @@ public:
     Option<Statistics<double>> statistics = None();
 
     if (data->history.isSome()) {
-      internal::acquire(&data->lock);
-      {
+      synchronized (data->lock) {
         statistics = Statistics<double>::from(*data->history.get());
       }
-      internal::release(&data->lock);
     }
 
     return statistics;
@@ -53,11 +52,9 @@ protected:
     if (data->history.isSome()) {
       Time now = Clock::now();
 
-      internal::acquire(&data->lock);
-      {
+      synchronized (data->lock) {
         data->history.get()->set(value, now);
       }
-      internal::release(&data->lock);
     }
   }
 
@@ -65,7 +62,7 @@ private:
   struct Data {
     Data(const std::string& _name, const Option<Duration>& window)
       : name(_name),
-        lock(0),
+        lock(ATOMIC_FLAG_INIT),
         history(None())
     {
       if (window.isSome()) {
@@ -76,7 +73,7 @@ private:
 
     const std::string name;
 
-    int lock;
+    std::atomic_flag lock;
 
     Option<Owned<TimeSeries<double>>> history;
   };


Mime
View raw message