Return-Path: X-Original-To: apmail-mesos-commits-archive@www.apache.org Delivered-To: apmail-mesos-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 99299187A0 for ; Thu, 4 Jun 2015 07:30:22 +0000 (UTC) Received: (qmail 99529 invoked by uid 500); 4 Jun 2015 07:30:22 -0000 Delivered-To: apmail-mesos-commits-archive@mesos.apache.org Received: (qmail 99473 invoked by uid 500); 4 Jun 2015 07:30:22 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 99306 invoked by uid 99); 4 Jun 2015 07:30:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jun 2015 07:30:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4B7A2E0FB0; Thu, 4 Jun 2015 07:30:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: benh@apache.org To: commits@mesos.apache.org Date: Thu, 04 Jun 2015 07:30:29 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [8/9] mesos git commit: Refactor Metrics::Metric to use synchronized. 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 Authored: Thu Jun 4 00:26:16 2015 -0700 Committer: Benjamin Hindman 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 #include #include #include -#include #include #include #include #include #include +#include namespace process { namespace metrics { @@ -33,11 +34,9 @@ public: Option> statistics = None(); if (data->history.isSome()) { - internal::acquire(&data->lock); - { + synchronized (data->lock) { statistics = Statistics::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& 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>> history; };