Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 370E42009A8 for ; Tue, 17 May 2016 18:05:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 35870160A1F; Tue, 17 May 2016 16:05:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 86DF11609F5 for ; Tue, 17 May 2016 18:05:24 +0200 (CEST) Received: (qmail 58155 invoked by uid 500); 17 May 2016 16:05:23 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 58024 invoked by uid 99); 17 May 2016 16:05:23 -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; Tue, 17 May 2016 16:05:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 745D7DFABB; Tue, 17 May 2016 16:05:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: eclark@apache.org To: commits@hbase.apache.org Date: Tue, 17 May 2016 16:05:24 -0000 Message-Id: <4ce4b3ee2a2846f4acce84556694d018@git.apache.org> In-Reply-To: <641d4cc158d74241a33da3ddfc0c6d1a@git.apache.org> References: <641d4cc158d74241a33da3ddfc0c6d1a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] hbase git commit: HBASE-15823 Use call once for user util archived-at: Tue, 17 May 2016 16:05:25 -0000 HBASE-15823 Use call once for user util Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/20f43d2f Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/20f43d2f Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/20f43d2f Branch: refs/heads/HBASE-14850 Commit: 20f43d2f519d686f5497d3a28d6decd6e908febe Parents: 2508b03 Author: Elliott Clark Authored: Fri May 13 13:07:03 2016 -0700 Committer: Elliott Clark Committed: Tue May 17 09:05:19 2016 -0700 ---------------------------------------------------------------------- hbase-native-client/utils/user-util.cc | 13 ++----------- hbase-native-client/utils/user-util.h | 6 ++---- 2 files changed, 4 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/20f43d2f/hbase-native-client/utils/user-util.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/utils/user-util.cc b/hbase-native-client/utils/user-util.cc index 3d963b3..9e170e0 100644 --- a/hbase-native-client/utils/user-util.cc +++ b/hbase-native-client/utils/user-util.cc @@ -27,22 +27,14 @@ using namespace hbase; using namespace std; -UserUtil::UserUtil() : init_{false}, user_name_{"drwho"}, m_() {} +UserUtil::UserUtil() : once_flag_{}, user_name_{"drwho"} {} string UserUtil::user_name() { - if (!init_) { - compute_user_name(); - } + std::call_once(once_flag_, [this]() { compute_user_name(); }); return user_name_; } void UserUtil::compute_user_name() { - lock_guard lock(m_); - - if (init_) { - return; - } - // According to the man page of getpwuid // this should never be free'd // @@ -52,6 +44,5 @@ void UserUtil::compute_user_name() { // make sure that we got something. if (passwd && passwd->pw_name) { user_name_ = string{passwd->pw_name}; - init_ = true; } } http://git-wip-us.apache.org/repos/asf/hbase/blob/20f43d2f/hbase-native-client/utils/user-util.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/utils/user-util.h b/hbase-native-client/utils/user-util.h index 0b4cc73..fdfc0c8 100644 --- a/hbase-native-client/utils/user-util.h +++ b/hbase-native-client/utils/user-util.h @@ -19,8 +19,7 @@ #pragma once -#include -#include +#include #include namespace hbase { @@ -49,8 +48,7 @@ private: * Compute the username. This will block. */ void compute_user_name(); - std::atomic init_; + std::once_flag once_flag_; std::string user_name_; - std::mutex m_; }; } // namespace hbase