You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by da...@apache.org on 2016/06/02 00:52:56 UTC

[4/5] incubator-kudu git commit: Replace kudu::{lock_guard, unique_lock} with std lib equivalents

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/tablet/transactions/write_transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.cc b/src/kudu/tablet/transactions/write_transaction.cc
index e7a6ba5..289e15c 100644
--- a/src/kudu/tablet/transactions/write_transaction.cc
+++ b/src/kudu/tablet/transactions/write_transaction.cc
@@ -327,7 +327,7 @@ void WriteTransactionState::Reset() {
 }
 
 void WriteTransactionState::ResetRpcFields() {
-  lock_guard<simple_spinlock> l(&txn_state_lock_);
+  std::lock_guard<simple_spinlock> l(txn_state_lock_);
   request_ = nullptr;
   response_ = nullptr;
   STLDeleteElements(&row_ops_);
@@ -346,7 +346,7 @@ string WriteTransactionState::ToString() const {
   // user data escaping into the log. See KUDU-387.
   string row_ops_str = "[";
   {
-    lock_guard<simple_spinlock> l(&txn_state_lock_);
+    std::lock_guard<simple_spinlock> l(txn_state_lock_);
     const size_t kMaxToStringify = 3;
     for (int i = 0; i < std::min(row_ops_.size(), kMaxToStringify); i++) {
       if (i > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/tablet/transactions/write_transaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.h b/src/kudu/tablet/transactions/write_transaction.h
index 1975fe5..0328ae0 100644
--- a/src/kudu/tablet/transactions/write_transaction.h
+++ b/src/kudu/tablet/transactions/write_transaction.h
@@ -18,6 +18,7 @@
 #ifndef KUDU_TABLET_WRITE_TRANSACTION_H_
 #define KUDU_TABLET_WRITE_TRANSACTION_H_
 
+#include <mutex>
 #include <string>
 #include <vector>
 
@@ -120,12 +121,12 @@ class WriteTransactionState : public TransactionState {
 
 
   void set_schema_at_decode_time(const Schema* schema) {
-    lock_guard<simple_spinlock> l(&txn_state_lock_);
+    std::lock_guard<simple_spinlock> l(txn_state_lock_);
     schema_at_decode_time_ = schema;
   }
 
   const Schema* schema_at_decode_time() const {
-    lock_guard<simple_spinlock> l(&txn_state_lock_);
+    std::lock_guard<simple_spinlock> l(txn_state_lock_);
     return schema_at_decode_time_;
   }
 
@@ -163,7 +164,7 @@ class WriteTransactionState : public TransactionState {
   }
 
   void swap_row_ops(std::vector<RowOp*>* new_ops) {
-    lock_guard<simple_spinlock> l(&txn_state_lock_);
+    std::lock_guard<simple_spinlock> l(txn_state_lock_);
     row_ops_.swap(*new_ops);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/tools/ksck.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/ksck.cc b/src/kudu/tools/ksck.cc
index 922506d..481141c 100644
--- a/src/kudu/tools/ksck.cc
+++ b/src/kudu/tools/ksck.cc
@@ -19,6 +19,7 @@
 
 #include <glog/logging.h>
 #include <iostream>
+#include <mutex>
 #include <unordered_set>
 
 #include "kudu/gutil/map-util.h"
@@ -209,7 +210,7 @@ class ChecksumResultReporter : public RefCountedThreadSafe<ChecksumResultReporte
                     const std::string& replica_uuid,
                     const Status& status,
                     uint64_t checksum) {
-    lock_guard<simple_spinlock> guard(&lock_);
+    std::lock_guard<simple_spinlock> guard(lock_);
     unordered_map<string, ResultPair>& replica_results =
         LookupOrInsert(&checksums_, tablet_id, unordered_map<string, ResultPair>());
     InsertOrDie(&replica_results, replica_uuid, ResultPair(status, checksum));
@@ -228,7 +229,7 @@ class ChecksumResultReporter : public RefCountedThreadSafe<ChecksumResultReporte
 
   // Get reported results.
   TabletResultMap checksums() const {
-    lock_guard<simple_spinlock> guard(&lock_);
+    std::lock_guard<simple_spinlock> guard(lock_);
     return checksums_;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/cache.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/cache.cc b/src/kudu/util/cache.cc
index 2157c71..7dd8e8e 100644
--- a/src/kudu/util/cache.cc
+++ b/src/kudu/util/cache.cc
@@ -4,6 +4,7 @@
 
 #include <glog/logging.h>
 #include <memory>
+#include <mutex>
 #include <stdlib.h>
 #include <string>
 #include <vector>
@@ -261,7 +262,7 @@ void LRUCache::LRU_Append(LRUHandle* e) {
 Cache::Handle* LRUCache::Lookup(const Slice& key, uint32_t hash, bool caching) {
   LRUHandle* e;
   {
-    lock_guard<MutexType> l(&mutex_);
+    std::lock_guard<MutexType> l(mutex_);
     e = table_.Lookup(key, hash);
     if (e != nullptr) {
       base::RefCountInc(&e->refs);
@@ -314,7 +315,7 @@ Cache::Handle* LRUCache::Insert(LRUHandle* e, Cache::EvictionCallback *eviction_
 
   LRUHandle* to_remove_head = nullptr;
   {
-    lock_guard<MutexType> l(&mutex_);
+    std::lock_guard<MutexType> l(mutex_);
 
     LRU_Append(e);
 
@@ -353,7 +354,7 @@ void LRUCache::Erase(const Slice& key, uint32_t hash) {
   LRUHandle* e;
   bool last_reference = false;
   {
-    lock_guard<MutexType> l(&mutex_);
+    std::lock_guard<MutexType> l(mutex_);
     e = table_.Remove(key, hash);
     if (e != nullptr) {
       LRU_Remove(e);
@@ -429,7 +430,7 @@ class ShardedLRUCache : public Cache {
     return reinterpret_cast<LRUHandle*>(handle)->value();
   }
   virtual uint64_t NewId() OVERRIDE {
-    lock_guard<MutexType> l(&id_mutex_);
+    std::lock_guard<MutexType> l(id_mutex_);
     return ++(last_id_);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/failure_detector.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/failure_detector.cc b/src/kudu/util/failure_detector.cc
index 426d345..c5c51a7 100644
--- a/src/kudu/util/failure_detector.cc
+++ b/src/kudu/util/failure_detector.cc
@@ -18,6 +18,7 @@
 #include "kudu/util/failure_detector.h"
 
 #include <glog/logging.h>
+#include <mutex>
 #include <unordered_map>
 
 #include "kudu/gutil/map-util.h"
@@ -45,7 +46,7 @@ TimedFailureDetector::~TimedFailureDetector() {
 Status TimedFailureDetector::Track(const string& name,
                                    const MonoTime& now,
                                    const FailureDetectedCallback& callback) {
-  lock_guard<simple_spinlock> lock(&lock_);
+  std::lock_guard<simple_spinlock> lock(lock_);
   gscoped_ptr<Node> node(new Node);
   node->permanent_name = name;
   node->callback = callback;
@@ -60,7 +61,7 @@ Status TimedFailureDetector::Track(const string& name,
 }
 
 Status TimedFailureDetector::UnTrack(const string& name) {
-  lock_guard<simple_spinlock> lock(&lock_);
+  std::lock_guard<simple_spinlock> lock(lock_);
   Node* node = EraseKeyReturnValuePtr(&nodes_, name);
   if (PREDICT_FALSE(node == NULL)) {
     return Status::NotFound(Substitute("Node with name '$0' not found", name));
@@ -70,13 +71,13 @@ Status TimedFailureDetector::UnTrack(const string& name) {
 }
 
 bool TimedFailureDetector::IsTracking(const std::string& name) {
-  lock_guard<simple_spinlock> lock(&lock_);
+  std::lock_guard<simple_spinlock> lock(lock_);
   return ContainsKey(nodes_, name);
 }
 
 Status TimedFailureDetector::MessageFrom(const std::string& name, const MonoTime& now) {
   VLOG(3) << "Received message from " << name << " at " << now.ToString();
-  lock_guard<simple_spinlock> lock(&lock_);
+  std::lock_guard<simple_spinlock> lock(lock_);
   Node* node = FindPtrOrNull(nodes_, name);
   if (node == NULL) {
     VLOG(1) << "Not tracking node: " << name;
@@ -100,7 +101,7 @@ void TimedFailureDetector::CheckForFailures(const MonoTime& now) {
   typedef unordered_map<string, FailureDetectedCallback> CallbackMap;
   CallbackMap callbacks;
   {
-    lock_guard<simple_spinlock> lock(&lock_);
+    std::lock_guard<simple_spinlock> lock(lock_);
     for (const NodeMap::value_type& entry : nodes_) {
       if (GetNodeStatusUnlocked(entry.first, now) == DEAD) {
         InsertOrDie(&callbacks, entry.first, entry.second->callback);
@@ -143,7 +144,7 @@ void RandomizedFailureMonitor::Shutdown() {
   }
 
   {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     if (shutdown_) {
       return;
     }
@@ -157,7 +158,7 @@ void RandomizedFailureMonitor::Shutdown() {
 
 Status RandomizedFailureMonitor::MonitorFailureDetector(const string& name,
                                                         const scoped_refptr<FailureDetector>& fd) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   bool inserted = InsertIfNotPresent(&fds_, name, fd);
   if (PREDICT_FALSE(!inserted)) {
     return Status::AlreadyPresent(Substitute("Already monitoring failure detector '$0'", name));
@@ -166,7 +167,7 @@ Status RandomizedFailureMonitor::MonitorFailureDetector(const string& name,
 }
 
 Status RandomizedFailureMonitor::UnmonitorFailureDetector(const string& name) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   int count = fds_.erase(name);
   if (PREDICT_FALSE(count == 0)) {
     return Status::NotFound(Substitute("Failure detector '$0' not found", name));
@@ -187,7 +188,7 @@ void RandomizedFailureMonitor::RunThread() {
     VLOG(3) << "RandomizedFailureMonitor sleeping for: " << wait_delta.ToString();
     if (run_latch_.WaitFor(wait_delta)) {
       // CountDownLatch reached 0.
-      lock_guard<simple_spinlock> lock(&lock_);
+      std::lock_guard<simple_spinlock> lock(lock_);
       // Check if we were told to shutdown.
       if (shutdown_) {
         // Latch fired: exit loop.
@@ -199,7 +200,7 @@ void RandomizedFailureMonitor::RunThread() {
     // Take a copy of the FD map under the lock.
     FDMap fds_copy;
     {
-      lock_guard<simple_spinlock> l(&lock_);
+      std::lock_guard<simple_spinlock> l(lock_);
       fds_copy = fds_;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/locks.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/locks.h b/src/kudu/util/locks.h
index 423f533..e305602 100644
--- a/src/kudu/util/locks.h
+++ b/src/kudu/util/locks.h
@@ -231,74 +231,9 @@ class percpu_rwlock {
   padded_lock *locks_;
 };
 
-// Simpler version of std::lock_guard. Only supports the basic object
-// lifecycle and defers any error checking to the underlying mutex.
-template <typename Mutex>
-class lock_guard {
- public:
-  explicit lock_guard(Mutex* m)
-    : m_(DCHECK_NOTNULL(m)) {
-    m_->lock();
-  }
-
-  ~lock_guard() {
-    m_->unlock();
-  }
-
- private:
-  Mutex* m_;
-  DISALLOW_COPY_AND_ASSIGN(lock_guard<Mutex>);
-};
-
-// Simpler version of boost::unique_lock. Tracks lock acquisition and will
-// report attempts to double lock() or unlock().
-template <typename Mutex>
-class unique_lock {
- public:
-  unique_lock()
-    : locked_(false),
-      m_(NULL) {
-  }
-
-  explicit unique_lock(Mutex* m)
-    : locked_(true),
-      m_(m) {
-    m_->lock();
-  }
-
-  ~unique_lock() {
-    if (locked_) {
-      m_->unlock();
-      locked_ = false;
-    }
-  }
-
-  void lock() {
-    DCHECK(!locked_);
-    m_->lock();
-    locked_ = true;
-  }
-
-  void unlock() {
-    DCHECK(locked_);
-    m_->unlock();
-    locked_ = false;
-  }
-
-  void swap(unique_lock<Mutex>* other) {
-    DCHECK(other != NULL) << "The passed unique_lock is null";
-    std::swap(locked_, other->locked_);
-    std::swap(m_, other->m_);
-  }
-
- private:
-  bool locked_;
-  Mutex* m_;
-  DISALLOW_COPY_AND_ASSIGN(unique_lock<Mutex>);
-};
-
-// Simpler version of boost::shared_lock. Defers error checking to the
-// underlying mutex.
+// Simple implementation of the std::shared_lock API, which is not available in
+// the standard library until C++17. Defers error checking to the underlying
+// mutex.
 template <typename Mutex>
 class shared_lock {
  public:

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/mem_tracker.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/mem_tracker.cc b/src/kudu/util/mem_tracker.cc
index 1a73284..1727780 100644
--- a/src/kudu/util/mem_tracker.cc
+++ b/src/kudu/util/mem_tracker.cc
@@ -23,6 +23,7 @@
 #include <limits>
 #include <list>
 #include <memory>
+#include <mutex>
 
 #include "kudu/gutil/map-util.h"
 #include "kudu/gutil/once.h"
@@ -461,7 +462,7 @@ bool MemTracker::GcMemory(int64_t max_consumption) {
     return true;
   }
 
-  lock_guard<simple_spinlock> l(&gc_lock_);
+  std::lock_guard<simple_spinlock> l(gc_lock_);
   if (!consumption_func_.empty()) {
     UpdateConsumption();
   }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/memory/arena.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/arena.cc b/src/kudu/util/memory/arena.cc
index 5f935df..106bd75 100644
--- a/src/kudu/util/memory/arena.cc
+++ b/src/kudu/util/memory/arena.cc
@@ -20,10 +20,10 @@
 #include "kudu/util/memory/arena.h"
 
 #include <algorithm>
+#include <mutex>
 
 #include "kudu/util/debug-util.h"
 #include "kudu/util/flag_tags.h"
-#include "kudu/util/locks.h"
 
 using std::copy;
 using std::max;
@@ -65,7 +65,7 @@ ArenaBase<THREADSAFE>::ArenaBase(size_t initial_buffer_size, size_t max_buffer_s
 
 template <bool THREADSAFE>
 void *ArenaBase<THREADSAFE>::AllocateBytesFallback(const size_t size, const size_t align) {
-  lock_guard<mutex_type> lock(&component_lock_);
+  std::lock_guard<mutex_type> lock(component_lock_);
 
   // It's possible another thread raced with us and already allocated
   // a new component, in which case we should try the "fast path" again
@@ -139,7 +139,7 @@ void ArenaBase<THREADSAFE>::AddComponent(ArenaBase::Component *component) {
 
 template <bool THREADSAFE>
 void ArenaBase<THREADSAFE>::Reset() {
-  lock_guard<mutex_type> lock(&component_lock_);
+  std::lock_guard<mutex_type> lock(component_lock_);
 
   if (PREDICT_FALSE(arena_.size() > 1)) {
     unique_ptr<Component> last = std::move(arena_.back());
@@ -163,7 +163,7 @@ void ArenaBase<THREADSAFE>::Reset() {
 
 template <bool THREADSAFE>
 size_t ArenaBase<THREADSAFE>::memory_footprint() const {
-  lock_guard<mutex_type> lock(&component_lock_);
+  std::lock_guard<mutex_type> lock(component_lock_);
   return arena_footprint_;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/memory/arena.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/arena.h b/src/kudu/util/memory/arena.h
index 4abd1d5..d192a56 100644
--- a/src/kudu/util/memory/arena.h
+++ b/src/kudu/util/memory/arena.h
@@ -26,18 +26,20 @@
 #include <boost/signals2/dummy_mutex.hpp>
 #include <glog/logging.h>
 #include <memory>
+#include <mutex>
 #include <new>
 #include <stddef.h>
 #include <string.h>
 #include <vector>
 
 #include "kudu/gutil/dynamic_annotations.h"
+#include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/logging-inl.h"
 #include "kudu/gutil/macros.h"
-#include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/util/alignment.h"
 #include "kudu/util/locks.h"
 #include "kudu/util/memory/memory.h"
+#include "kudu/util/mutex.h"
 #include "kudu/util/slice.h"
 
 using std::allocator;
@@ -426,7 +428,7 @@ inline uint8_t *ArenaBase<false>::Component::AllocateBytesAligned(
 template <bool THREADSAFE>
 inline void ArenaBase<THREADSAFE>::Component::AsanUnpoison(const void* addr, size_t size) {
 #ifdef ADDRESS_SANITIZER
-  lock_guard<spinlock_type> l(&asan_lock_);
+  std::lock_guard<spinlock_type> l(asan_lock_);
   ASAN_UNPOISON_MEMORY_REGION(addr, size);
 #endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/metrics.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc
index 2935cbc..31e2d50 100644
--- a/src/kudu/util/metrics.cc
+++ b/src/kudu/util/metrics.cc
@@ -170,7 +170,7 @@ void MetricEntity::CheckInstantiation(const MetricPrototype* proto) const {
 }
 
 scoped_refptr<Metric> MetricEntity::FindOrNull(const MetricPrototype& prototype) const {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   return FindPtrOrNull(metric_map_, &prototype);
 }
 
@@ -203,7 +203,7 @@ Status MetricEntity::WriteAsJson(JsonWriter* writer,
   AttributeMap attrs;
   {
     // Snapshot the metrics in this registry (not guaranteed to be a consistent snapshot)
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     attrs = attributes_;
     for (const MetricMap::value_type& val : metric_map_) {
       const MetricPrototype* prototype = val.first;
@@ -254,7 +254,7 @@ Status MetricEntity::WriteAsJson(JsonWriter* writer,
 void MetricEntity::RetireOldMetrics() {
   MonoTime now(MonoTime::Now(MonoTime::FINE));
 
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   for (auto it = metric_map_.begin(); it != metric_map_.end();) {
     const scoped_refptr<Metric>& metric = it->second;
 
@@ -298,17 +298,17 @@ void MetricEntity::RetireOldMetrics() {
 }
 
 void MetricEntity::NeverRetire(const scoped_refptr<Metric>& metric) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   never_retire_metrics_.push_back(metric);
 }
 
 void MetricEntity::SetAttributes(const AttributeMap& attrs) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   attributes_ = attrs;
 }
 
 void MetricEntity::SetAttribute(const string& key, const string& val) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   attributes_[key] = val;
 }
 
@@ -327,7 +327,7 @@ Status MetricRegistry::WriteAsJson(JsonWriter* writer,
                                    const MetricJsonOptions& opts) const {
   EntityMap entities;
   {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     entities = entities_;
   }
 
@@ -349,7 +349,7 @@ Status MetricRegistry::WriteAsJson(JsonWriter* writer,
 }
 
 void MetricRegistry::RetireOldMetrics() {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   for (auto it = entities_.begin(); it != entities_.end();) {
     it->second->RetireOldMetrics();
 
@@ -373,17 +373,17 @@ MetricPrototypeRegistry* MetricPrototypeRegistry::get() {
 }
 
 void MetricPrototypeRegistry::AddMetric(const MetricPrototype* prototype) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   metrics_.push_back(prototype);
 }
 
 void MetricPrototypeRegistry::AddEntity(const MetricEntityPrototype* prototype) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   entities_.push_back(prototype);
 }
 
 void MetricPrototypeRegistry::WriteAsJson(JsonWriter* writer) const {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   MetricJsonOptions opts;
   opts.include_schema_info = true;
   writer->StartObject();
@@ -466,7 +466,7 @@ scoped_refptr<MetricEntity> MetricRegistry::FindOrCreateEntity(
     const MetricEntityPrototype* prototype,
     const std::string& id,
     const MetricEntity::AttributeMap& initial_attributes) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   scoped_refptr<MetricEntity> e = FindPtrOrNull(entities_, id);
   if (!e) {
     e = new MetricEntity(prototype, id, initial_attributes);
@@ -513,12 +513,12 @@ StringGauge::StringGauge(const GaugePrototype<string>* proto,
     : Gauge(proto), value_(std::move(initial_value)) {}
 
 std::string StringGauge::value() const {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   return value_;
 }
 
 void StringGauge::set_value(const std::string& value) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   value_ = value;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/metrics.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/metrics.h b/src/kudu/util/metrics.h
index b55cd08..4952410 100644
--- a/src/kudu/util/metrics.h
+++ b/src/kudu/util/metrics.h
@@ -224,6 +224,7 @@
 /////////////////////////////////////////////////////
 
 #include <algorithm>
+#include <mutex>
 #include <string>
 #include <unordered_map>
 #include <vector>
@@ -486,7 +487,7 @@ class MetricEntity : public RefCountedThreadSafe<MetricEntity> {
   void SetAttribute(const std::string& key, const std::string& val);
 
   int num_metrics() const {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return metric_map_.size();
   }
 
@@ -580,7 +581,7 @@ class MetricRegistry {
 
   // Return the number of entities in this registry.
   int num_entities() const {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return entities_.size();
   }
 
@@ -850,7 +851,7 @@ template <typename T>
 class FunctionGauge : public Gauge {
  public:
   T value() const {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return function_.Run();
   }
 
@@ -862,7 +863,7 @@ class FunctionGauge : public Gauge {
   // This should be used during destruction. If you want a settable
   // Gauge, use a normal Gauge instead of a FunctionGauge.
   void DetachToConstant(T v) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     function_ = Bind(&FunctionGauge::Return, v);
   }
 
@@ -1019,7 +1020,7 @@ class ScopedLatencyMetric {
 inline scoped_refptr<Counter> MetricEntity::FindOrCreateCounter(
     const CounterPrototype* proto) {
   CheckInstantiation(proto);
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   scoped_refptr<Counter> m = down_cast<Counter*>(FindPtrOrNull(metric_map_, proto).get());
   if (!m) {
     m = new Counter(proto);
@@ -1031,7 +1032,7 @@ inline scoped_refptr<Counter> MetricEntity::FindOrCreateCounter(
 inline scoped_refptr<Histogram> MetricEntity::FindOrCreateHistogram(
     const HistogramPrototype* proto) {
   CheckInstantiation(proto);
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   scoped_refptr<Histogram> m = down_cast<Histogram*>(FindPtrOrNull(metric_map_, proto).get());
   if (!m) {
     m = new Histogram(proto);
@@ -1045,7 +1046,7 @@ inline scoped_refptr<AtomicGauge<T> > MetricEntity::FindOrCreateGauge(
     const GaugePrototype<T>* proto,
     const T& initial_value) {
   CheckInstantiation(proto);
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   scoped_refptr<AtomicGauge<T> > m = down_cast<AtomicGauge<T>*>(
       FindPtrOrNull(metric_map_, proto).get());
   if (!m) {
@@ -1060,7 +1061,7 @@ inline scoped_refptr<FunctionGauge<T> > MetricEntity::FindOrCreateFunctionGauge(
     const GaugePrototype<T>* proto,
     const Callback<T()>& function) {
   CheckInstantiation(proto);
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   scoped_refptr<FunctionGauge<T> > m = down_cast<FunctionGauge<T>*>(
       FindPtrOrNull(metric_map_, proto).get());
   if (!m) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/nvm_cache.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/nvm_cache.cc b/src/kudu/util/nvm_cache.cc
index c8a3465..678aa87 100644
--- a/src/kudu/util/nvm_cache.cc
+++ b/src/kudu/util/nvm_cache.cc
@@ -25,6 +25,7 @@
 #include <iostream>
 #include <libvmem.h>
 #include <memory>
+#include <mutex>
 #include <stdlib.h>
 #include <string>
 #include <vector>
@@ -299,7 +300,7 @@ void *NvmLRUCache::AllocateAndRetry(size_t size) {
   tmp = VmemMalloc(size);
 
   if (tmp == NULL) {
-    unique_lock<MutexType> l(&mutex_);
+    std::unique_lock<MutexType> l(mutex_);
 
     int retries_remaining = FLAGS_nvm_cache_allocation_retry_count;
     while (tmp == NULL && retries_remaining-- > 0 && lru_.next != &lru_) {
@@ -336,7 +337,7 @@ void NvmLRUCache::NvmLRU_Append(LRUHandle* e) {
 Cache::Handle* NvmLRUCache::Lookup(const Slice& key, uint32_t hash, bool caching) {
  LRUHandle* e;
   {
-    lock_guard<MutexType> l(&mutex_);
+    std::lock_guard<MutexType> l(mutex_);
     e = table_.Lookup(key, hash);
     if (e != NULL) {
       // If an entry exists, remove the old entry from the cache
@@ -408,7 +409,7 @@ Cache::Handle* NvmLRUCache::Insert(LRUHandle* e,
   }
 
   {
-    lock_guard<MutexType> l(&mutex_);
+    std::lock_guard<MutexType> l(mutex_);
 
     NvmLRU_Append(e);
 
@@ -437,7 +438,7 @@ void NvmLRUCache::Erase(const Slice& key, uint32_t hash) {
   LRUHandle* e;
   bool last_reference = false;
   {
-    lock_guard<MutexType> l(&mutex_);
+    std::lock_guard<MutexType> l(mutex_);
     e = table_.Remove(key, hash);
     if (e != NULL) {
       NvmLRU_Remove(e);
@@ -516,7 +517,7 @@ class ShardedLRUCache : public Cache {
   }
 
   virtual uint64_t NewId() OVERRIDE {
-    lock_guard<MutexType> l(&id_mutex_);
+    std::lock_guard<MutexType> l(id_mutex_);
     return ++(last_id_);
   }
   virtual void SetMetrics(const scoped_refptr<MetricEntity>& entity) OVERRIDE {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/path_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/path_util.cc b/src/kudu/util/path_util.cc
index 872886b..7131431 100644
--- a/src/kudu/util/path_util.cc
+++ b/src/kudu/util/path_util.cc
@@ -26,7 +26,7 @@
 #include "kudu/gutil/gscoped_ptr.h"
 
 #if defined(__APPLE__)
-#include "kudu/util/locks.h"
+#include <mutex>
 #endif // defined(__APPLE__)
 
 using std::string;
@@ -49,8 +49,8 @@ std::string JoinPathSegments(const std::string &a,
 string DirName(const string& path) {
   gscoped_ptr<char[], FreeDeleter> path_copy(strdup(path.c_str()));
 #if defined(__APPLE__)
-  static Mutex lock;
-  lock_guard<Mutex> l(&lock);
+  static std::mutex lock;
+  std::lock_guard<std::mutex> l(lock);
 #endif // defined(__APPLE__)
   return ::dirname(path_copy.get());
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/random.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/random.h b/src/kudu/util/random.h
index c466229..8f9ab22 100644
--- a/src/kudu/util/random.h
+++ b/src/kudu/util/random.h
@@ -6,6 +6,7 @@
 
 #include <cmath>
 #include <cstdint>
+#include <mutex>
 #include <random>
 #include <vector>
 
@@ -158,59 +159,59 @@ class ThreadSafeRandom {
   }
 
   void Reset(uint32_t s) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     random_.Reset(s);
   }
 
   uint32_t Next() {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Next();
   }
 
   uint32_t Next32() {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Next32();
   }
 
   uint64_t Next64() {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Next64();
   }
 
   uint32_t Uniform(uint32_t n) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Uniform(n);
   }
 
   uint32_t Uniform32(uint32_t n) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Uniform32(n);
   }
 
   uint64_t Uniform64(uint64_t n) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Uniform64(n);
   }
 
   bool OneIn(int n) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.OneIn(n);
   }
 
   uint32_t Skewed(int max_log) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Skewed(max_log);
   }
 
   double Normal(double mean, double std_dev) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     return random_.Normal(mean, std_dev);
   }
 
   template<class Collection, class Set, class T>
   void ReservoirSample(const Collection& c, int k, const Set& avoid,
                        std::vector<T>* result) {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     random_.ReservoirSample(c, k, avoid, result);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/resettable_heartbeater.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/resettable_heartbeater.cc b/src/kudu/util/resettable_heartbeater.cc
index a1c68b9..91c4587 100644
--- a/src/kudu/util/resettable_heartbeater.cc
+++ b/src/kudu/util/resettable_heartbeater.cc
@@ -15,10 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include <glog/logging.h>
-
 #include "kudu/util/resettable_heartbeater.h"
 
+#include <glog/logging.h>
+#include <mutex>
+
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/util/countdown_latch.h"
@@ -115,7 +116,7 @@ void ResettableHeartbeaterThread::RunThread() {
     if (run_latch_.WaitFor(wait_period)) {
       // CountDownLatch reached 0 -- this means there was a manual reset.
       prev_reset_was_manual = true;
-      lock_guard<simple_spinlock> lock(&lock_);
+      std::lock_guard<simple_spinlock> lock(lock_);
       // check if we were told to shutdown
       if (shutdown_) {
         // Latch fired -- exit loop
@@ -163,7 +164,7 @@ Status ResettableHeartbeaterThread::Stop() {
   }
 
   {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     if (shutdown_) {
       return Status::OK();
     }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/test_graph.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/test_graph.cc b/src/kudu/util/test_graph.cc
index c3dc9e1..052ad9c 100644
--- a/src/kudu/util/test_graph.cc
+++ b/src/kudu/util/test_graph.cc
@@ -15,14 +15,16 @@
 // specific language governing permissions and limitations
 // under the License.
 
+#include "kudu/util/test_graph.h"
+
 #include <glog/logging.h>
+#include <mutex>
 
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/gutil/stringprintf.h"
 #include "kudu/gutil/walltime.h"
 #include "kudu/util/locks.h"
 #include "kudu/util/status.h"
-#include "kudu/util/test_graph.h"
 #include "kudu/util/thread.h"
 
 using std::shared_ptr;
@@ -31,17 +33,17 @@ using std::string;
 namespace kudu {
 
 void TimeSeries::AddValue(double val) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   val_ += val;
 }
 
 void TimeSeries::SetValue(double val) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   val_ = val;
 }
 
 double TimeSeries::value() const {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   return val_;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/trace.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/trace.cc b/src/kudu/util/trace.cc
index 9b556b5..f5793cb 100644
--- a/src/kudu/util/trace.cc
+++ b/src/kudu/util/trace.cc
@@ -21,6 +21,7 @@
 #include <ios>
 #include <iostream>
 #include <map>
+#include <mutex>
 #include <string>
 #include <strstream>
 #include <utility>
@@ -106,7 +107,7 @@ TraceEntry* Trace::NewEntry(int msg_len, const char* file_path, int line_number)
 }
 
 void Trace::AddEntry(TraceEntry* entry) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   entry->next = nullptr;
 
   if (entries_tail_ != nullptr) {
@@ -126,7 +127,7 @@ void Trace::Dump(std::ostream* out, int flags) const {
   vector<TraceEntry*> entries;
   vector<pair<StringPiece, scoped_refptr<Trace>>> child_traces;
   {
-    lock_guard<simple_spinlock> l(&lock_);
+    std::lock_guard<simple_spinlock> l(lock_);
     for (TraceEntry* cur = entries_head_;
          cur != nullptr;
          cur = cur->next) {
@@ -241,13 +242,13 @@ void Trace::DumpCurrentTrace() {
 void Trace::AddChildTrace(StringPiece label, Trace* child_trace) {
   CHECK(arena_->RelocateStringPiece(label, &label));
 
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   scoped_refptr<Trace> ptr(child_trace);
   child_traces_.emplace_back(label, ptr);
 }
 
 std::vector<std::pair<StringPiece, scoped_refptr<Trace>>> Trace::ChildTraces() const {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   return child_traces_;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/trace_metrics.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/trace_metrics.cc b/src/kudu/util/trace_metrics.cc
index 20569fc..32ff1c4 100644
--- a/src/kudu/util/trace_metrics.cc
+++ b/src/kudu/util/trace_metrics.cc
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <glog/stl_logging.h>
 #include <map>
+#include <mutex>
 #include <string>
 
 #include "kudu/util/debug/leakcheck_disabler.h"
@@ -42,7 +43,7 @@ const char* TraceMetrics::InternName(const string& name) {
       << "not printable: " << name;
 
   debug::ScopedLeakCheckDisabler no_leakcheck;
-  lock_guard<simple_spinlock> l(&g_intern_map_lock);
+  std::lock_guard<simple_spinlock> l(g_intern_map_lock);
   if (g_intern_map == nullptr) {
     g_intern_map = new InternMap();
   }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/8a75ceee/src/kudu/util/trace_metrics.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/trace_metrics.h b/src/kudu/util/trace_metrics.h
index 4ef6d63..fbe1774 100644
--- a/src/kudu/util/trace_metrics.h
+++ b/src/kudu/util/trace_metrics.h
@@ -21,6 +21,7 @@
 #include "kudu/util/locks.h"
 
 #include <map>
+#include <mutex>
 #include <string>
 
 namespace kudu {
@@ -73,12 +74,12 @@ class TraceMetrics {
 };
 
 inline void TraceMetrics::Increment(const char* name, int64_t amount) {
-  lock_guard<simple_spinlock> l(&lock_);
+  std::lock_guard<simple_spinlock> l(lock_);
   counters_[name] += amount;
 }
 
 inline std::map<const char*, int64_t> TraceMetrics::Get() const {
-  unique_lock<simple_spinlock> l(&lock_);
+  std::unique_lock<simple_spinlock> l(lock_);
   auto m = counters_;
   l.unlock();