EDK: Move mutex.*, cond_var.*, and thread_annotations.h to //mojo/edk/util.

(Also, make them not depend on //base/logging.h. Add some simple logging
macros for those needs.)

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/1426343002 .
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 769b783..d7195a6 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -642,6 +642,7 @@
                 (r"^base/logging\.h$",
                  r"^base/logging\.cc$",
                  r"^examples/.*$",
+                 r"^mojo/edk/util/logging_internal\.cc$",
                  r"^mojo/nacl/sfi/nacl_bindings/mojo_syscall\.cc$",
                  r"^shell/application_manager/network_fetcher\.cc$",
                  r"^shell/tracer\.cc$",
diff --git a/mojo/edk/embedder/BUILD.gn b/mojo/edk/embedder/BUILD.gn
index 5d32e37..f80f11b 100644
--- a/mojo/edk/embedder/BUILD.gn
+++ b/mojo/edk/embedder/BUILD.gn
@@ -120,7 +120,6 @@
 
   deps = [
     "//base",
-    "//base/test:test_support",
     "//testing/gtest",
   ]
 
diff --git a/mojo/edk/embedder/embedder_unittest.cc b/mojo/edk/embedder/embedder_unittest.cc
index b12f69d..86c46e0 100644
--- a/mojo/edk/embedder/embedder_unittest.cc
+++ b/mojo/edk/embedder/embedder_unittest.cc
@@ -14,12 +14,13 @@
 #include "base/message_loop/message_loop.h"
 #include "mojo/edk/embedder/platform_channel_pair.h"
 #include "mojo/edk/embedder/test_embedder.h"
-#include "mojo/edk/system/mutex.h"
 #include "mojo/edk/system/test/test_io_thread.h"
 #include "mojo/edk/system/test/timeouts.h"
 #include "mojo/edk/system/waitable_event.h"
 #include "mojo/edk/test/multiprocess_test_helper.h"
 #include "mojo/edk/test/scoped_ipc_support.h"
+#include "mojo/edk/util/mutex.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/core.h"
 #include "mojo/public/cpp/system/handle.h"
 #include "mojo/public/cpp/system/macros.h"
@@ -27,6 +28,8 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 using mojo::system::test::TestIOThread;
+using mojo::util::Mutex;
+using mojo::util::MutexLocker;
 
 namespace mojo {
 namespace embedder {
@@ -196,7 +199,7 @@
   TestAsyncWaiter() : wait_result_(MOJO_RESULT_UNKNOWN) {}
 
   void Awake(MojoResult result) {
-    system::MutexLocker l(&wait_result_mutex_);
+    MutexLocker l(&wait_result_mutex_);
     wait_result_ = result;
     event_.Signal();
   }
@@ -206,14 +209,14 @@
   }
 
   MojoResult wait_result() const {
-    system::MutexLocker l(&wait_result_mutex_);
+    MutexLocker l(&wait_result_mutex_);
     return wait_result_;
   }
 
  private:
   mojo::system::ManualResetWaitableEvent event_;
 
-  mutable system::Mutex wait_result_mutex_;
+  mutable Mutex wait_result_mutex_;
   MojoResult wait_result_ MOJO_GUARDED_BY(wait_result_mutex_);
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter);
diff --git a/mojo/edk/system/BUILD.gn b/mojo/edk/system/BUILD.gn
index 14c7bf8..b6461a2 100644
--- a/mojo/edk/system/BUILD.gn
+++ b/mojo/edk/system/BUILD.gn
@@ -33,8 +33,6 @@
     "channel_id.h",
     "channel_manager.cc",
     "channel_manager.h",
-    "cond_var.cc",
-    "cond_var.h",
     "configuration.cc",
     "configuration.h",
     "connection_identifier.h",
@@ -82,8 +80,6 @@
     "message_pipe_dispatcher.h",
     "message_pipe_endpoint.cc",
     "message_pipe_endpoint.h",
-    "mutex.cc",
-    "mutex.h",
     "options_validation.h",
     "platform_handle_dispatcher.cc",
     "platform_handle_dispatcher.h",
@@ -104,7 +100,6 @@
     "simple_dispatcher.h",
     "slave_connection_manager.cc",
     "slave_connection_manager.h",
-    "thread_annotations.h",
     "transport_data.cc",
     "transport_data.h",
     "unique_identifier.cc",
@@ -152,7 +147,6 @@
     "channel_test_base.cc",
     "channel_test_base.h",
     "channel_unittest.cc",
-    "cond_var_unittest.cc",
     "connection_manager_unittest.cc",
     "core_test_base.cc",
     "core_test_base.h",
@@ -171,7 +165,6 @@
     "message_pipe_test_utils.h",
     "message_pipe_unittest.cc",
     "multiprocess_message_pipe_unittest.cc",
-    "mutex_unittest.cc",
     "options_validation_unittest.cc",
     "platform_handle_dispatcher_unittest.cc",
     "raw_channel_unittest.cc",
@@ -181,7 +174,6 @@
     "simple_dispatcher_unittest.cc",
     "test_channel_endpoint_client.cc",
     "test_channel_endpoint_client.h",
-    "thread_annotations_unittest.cc",
     "unique_identifier_unittest.cc",
     "waitable_event_unittest.cc",
     "waiter_test_utils.cc",
diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc
index 952759a..61fd80f 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -15,6 +15,7 @@
 #include "mojo/edk/system/transport_data.h"
 
 using mojo::util::MakeRefCounted;
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/channel.h b/mojo/edk/system/channel.h
index 1f76d1d..1828d43 100644
--- a/mojo/edk/system/channel.h
+++ b/mojo/edk/system/channel.h
@@ -16,10 +16,11 @@
 #include "mojo/edk/system/channel_endpoint_id.h"
 #include "mojo/edk/system/incoming_endpoint.h"
 #include "mojo/edk/system/message_in_transit.h"
-#include "mojo/edk/system/mutex.h"
 #include "mojo/edk/system/raw_channel.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_counted.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/types.h"
 #include "mojo/public/cpp/system/macros.h"
 
@@ -248,7 +249,7 @@
   // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|,
   // once clang actually checks such annotations.
   // https://github.com/domokit/mojo/issues/313
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
 
   std::unique_ptr<RawChannel> raw_channel_ MOJO_GUARDED_BY(mutex_);
   bool is_running_ MOJO_GUARDED_BY(mutex_);
diff --git a/mojo/edk/system/channel_endpoint.cc b/mojo/edk/system/channel_endpoint.cc
index 9010fdb..8d8ecc1 100644
--- a/mojo/edk/system/channel_endpoint.cc
+++ b/mojo/edk/system/channel_endpoint.cc
@@ -12,6 +12,7 @@
 #include "mojo/edk/system/channel_endpoint_client.h"
 #include "mojo/public/cpp/system/macros.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/channel_endpoint.h b/mojo/edk/system/channel_endpoint.h
index 4a720f2..fca0e9e 100644
--- a/mojo/edk/system/channel_endpoint.h
+++ b/mojo/edk/system/channel_endpoint.h
@@ -9,9 +9,10 @@
 
 #include "mojo/edk/system/channel_endpoint_id.h"
 #include "mojo/edk/system/message_in_transit_queue.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_counted.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
@@ -178,7 +179,7 @@
   // this does not call |channel_->DetachEndpoint()|.
   void DieNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
 
-  Mutex mutex_;
+  util::Mutex mutex_;
 
   enum class State {
     // |AttachAndRun()| has not been called yet (|channel_| is null).
diff --git a/mojo/edk/system/channel_manager.cc b/mojo/edk/system/channel_manager.cc
index 8f9bbbe..ca0c270 100644
--- a/mojo/edk/system/channel_manager.cc
+++ b/mojo/edk/system/channel_manager.cc
@@ -13,6 +13,7 @@
 #include "mojo/edk/system/message_pipe_dispatcher.h"
 
 using mojo::util::MakeRefCounted;
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/channel_manager.h b/mojo/edk/system/channel_manager.h
index da3f292..1ef217b 100644
--- a/mojo/edk/system/channel_manager.h
+++ b/mojo/edk/system/channel_manager.h
@@ -13,8 +13,9 @@
 #include "mojo/edk/embedder/platform_task_runner.h"
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/edk/system/channel_id.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace base {
@@ -152,7 +153,7 @@
   // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|,
   // once clang actually checks such annotations.
   // https://github.com/domokit/mojo/issues/313
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
 
   using ChannelIdToChannelMap =
       std::unordered_map<ChannelId, util::RefPtr<Channel>>;
diff --git a/mojo/edk/system/connection_manager.h b/mojo/edk/system/connection_manager.h
index 7cc0801..13d7584 100644
--- a/mojo/edk/system/connection_manager.h
+++ b/mojo/edk/system/connection_manager.h
@@ -9,7 +9,7 @@
 
 #include "mojo/edk/system/connection_identifier.h"
 #include "mojo/edk/system/process_identifier.h"
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/core.cc b/mojo/edk/system/core.cc
index b2a74ae..8e1340f 100644
--- a/mojo/edk/system/core.cc
+++ b/mojo/edk/system/core.cc
@@ -26,6 +26,7 @@
 #include "mojo/public/c/system/macros.h"
 #include "mojo/public/cpp/system/macros.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/core.h b/mojo/edk/system/core.h
index 59fcee8..c8a47e0 100644
--- a/mojo/edk/system/core.h
+++ b/mojo/edk/system/core.h
@@ -11,8 +11,9 @@
 #include "mojo/edk/system/handle_table.h"
 #include "mojo/edk/system/mapping_table.h"
 #include "mojo/edk/system/memory.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/buffer.h"
 #include "mojo/public/c/system/data_pipe.h"
 #include "mojo/public/c/system/message_pipe.h"
@@ -175,10 +176,10 @@
 
   // TODO(vtl): |handle_table_mutex_| should be a reader-writer lock (if only we
   // had them).
-  Mutex handle_table_mutex_;
+  util::Mutex handle_table_mutex_;
   HandleTable handle_table_ MOJO_GUARDED_BY(handle_table_mutex_);
 
-  Mutex mapping_table_mutex_;
+  util::Mutex mapping_table_mutex_;
   MappingTable mapping_table_ MOJO_GUARDED_BY(mapping_table_mutex_);
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(Core);
diff --git a/mojo/edk/system/core_test_base.cc b/mojo/edk/system/core_test_base.cc
index 5ab13b0..9048070 100644
--- a/mojo/edk/system/core_test_base.cc
+++ b/mojo/edk/system/core_test_base.cc
@@ -14,6 +14,7 @@
 #include "mojo/edk/util/ref_ptr.h"
 #include "mojo/public/cpp/system/macros.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/core_test_base.h b/mojo/edk/system/core_test_base.h
index e2375cd..0e9c14c 100644
--- a/mojo/edk/system/core_test_base.h
+++ b/mojo/edk/system/core_test_base.h
@@ -6,7 +6,8 @@
 #define MOJO_EDK_SYSTEM_CORE_TEST_BASE_H_
 
 #include "mojo/edk/embedder/simple_platform_support.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/types.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -88,7 +89,7 @@
   void AwakableWasAdded(Awakable*);
 
  private:
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
   unsigned ctor_call_count_ MOJO_GUARDED_BY(mutex_);
   unsigned dtor_call_count_ MOJO_GUARDED_BY(mutex_);
   unsigned close_call_count_ MOJO_GUARDED_BY(mutex_);
diff --git a/mojo/edk/system/data_pipe.cc b/mojo/edk/system/data_pipe.cc
index 3a089d9..7cfd2a5 100644
--- a/mojo/edk/system/data_pipe.cc
+++ b/mojo/edk/system/data_pipe.cc
@@ -25,6 +25,7 @@
 #include "mojo/edk/system/remote_producer_data_pipe_impl.h"
 #include "mojo/edk/util/make_unique.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/data_pipe.h b/mojo/edk/system/data_pipe.h
index ef39ba3..62fe5aa 100644
--- a/mojo/edk/system/data_pipe.h
+++ b/mojo/edk/system/data_pipe.h
@@ -14,9 +14,9 @@
 #include "mojo/edk/system/channel_endpoint_client.h"
 #include "mojo/edk/system/handle_signals_state.h"
 #include "mojo/edk/system/memory.h"
-#include "mojo/edk/system/mutex.h"
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/data_pipe.h"
 #include "mojo/public/c/system/types.h"
 #include "mojo/public/cpp/system/macros.h"
@@ -265,7 +265,7 @@
   MSVC_SUPPRESS_WARNING(4324)
   const MojoCreateDataPipeOptions validated_options_;
 
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
   // *Known* state of producer or consumer.
   bool producer_open_ MOJO_GUARDED_BY(mutex_);
   bool consumer_open_ MOJO_GUARDED_BY(mutex_);
diff --git a/mojo/edk/system/data_pipe_consumer_dispatcher.cc b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
index 664d974..490b917 100644
--- a/mojo/edk/system/data_pipe_consumer_dispatcher.cc
+++ b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
@@ -10,6 +10,7 @@
 #include "mojo/edk/system/data_pipe.h"
 #include "mojo/edk/system/memory.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/data_pipe_consumer_dispatcher.h b/mojo/edk/system/data_pipe_consumer_dispatcher.h
index dbf628b..9f2389d 100644
--- a/mojo/edk/system/data_pipe_consumer_dispatcher.h
+++ b/mojo/edk/system/data_pipe_consumer_dispatcher.h
@@ -7,6 +7,7 @@
 
 #include "mojo/edk/system/dispatcher.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/data_pipe_impl.h b/mojo/edk/system/data_pipe_impl.h
index 6dfddc7..87464c8 100644
--- a/mojo/edk/system/data_pipe_impl.h
+++ b/mojo/edk/system/data_pipe_impl.h
@@ -13,7 +13,7 @@
 #include "mojo/edk/system/data_pipe.h"
 #include "mojo/edk/system/handle_signals_state.h"
 #include "mojo/edk/system/memory.h"
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/data_pipe.h"
 #include "mojo/public/c/system/macros.h"
 #include "mojo/public/c/system/types.h"
diff --git a/mojo/edk/system/data_pipe_producer_dispatcher.cc b/mojo/edk/system/data_pipe_producer_dispatcher.cc
index 19f8baa..814fa59 100644
--- a/mojo/edk/system/data_pipe_producer_dispatcher.cc
+++ b/mojo/edk/system/data_pipe_producer_dispatcher.cc
@@ -10,6 +10,7 @@
 #include "mojo/edk/system/data_pipe.h"
 #include "mojo/edk/system/memory.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/data_pipe_producer_dispatcher.h b/mojo/edk/system/data_pipe_producer_dispatcher.h
index 79097d9..9251ce1 100644
--- a/mojo/edk/system/data_pipe_producer_dispatcher.h
+++ b/mojo/edk/system/data_pipe_producer_dispatcher.h
@@ -7,6 +7,7 @@
 
 #include "mojo/edk/system/dispatcher.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/dispatcher.cc b/mojo/edk/system/dispatcher.cc
index 1ff0d29..ea88870 100644
--- a/mojo/edk/system/dispatcher.cc
+++ b/mojo/edk/system/dispatcher.cc
@@ -12,6 +12,7 @@
 #include "mojo/edk/system/platform_handle_dispatcher.h"
 #include "mojo/edk/system/shared_buffer_dispatcher.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/dispatcher.h b/mojo/edk/system/dispatcher.h
index 8c78434..e425bb3 100644
--- a/mojo/edk/system/dispatcher.h
+++ b/mojo/edk/system/dispatcher.h
@@ -15,9 +15,10 @@
 #include "mojo/edk/embedder/platform_handle_vector.h"
 #include "mojo/edk/system/handle_signals_state.h"
 #include "mojo/edk/system/memory.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_counted.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/buffer.h"
 #include "mojo/public/c/system/data_pipe.h"
 #include "mojo/public/c/system/message_pipe.h"
@@ -310,7 +311,7 @@
   // handle from being sent over a message pipe (with status "busy").
   virtual bool IsBusyNoLock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_);
 
-  Mutex& mutex() const MOJO_LOCK_RETURNED(mutex_) { return mutex_; }
+  util::Mutex& mutex() const MOJO_LOCK_RETURNED(mutex_) { return mutex_; }
 
  private:
   FRIEND_REF_COUNTED_THREAD_SAFE(Dispatcher);
@@ -375,7 +376,7 @@
 
   // This protects the following members as well as any state added by
   // subclasses.
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
   bool is_closed_ MOJO_GUARDED_BY(mutex_);
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher);
diff --git a/mojo/edk/system/endpoint_relayer.cc b/mojo/edk/system/endpoint_relayer.cc
index 434554b..3d7b8d1 100644
--- a/mojo/edk/system/endpoint_relayer.cc
+++ b/mojo/edk/system/endpoint_relayer.cc
@@ -10,6 +10,7 @@
 #include "mojo/edk/system/channel_endpoint.h"
 #include "mojo/edk/system/message_in_transit.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/endpoint_relayer.h b/mojo/edk/system/endpoint_relayer.h
index 036eaa3..bb06894 100644
--- a/mojo/edk/system/endpoint_relayer.h
+++ b/mojo/edk/system/endpoint_relayer.h
@@ -8,8 +8,9 @@
 #include <memory>
 
 #include "mojo/edk/system/channel_endpoint_client.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
@@ -84,7 +85,7 @@
   EndpointRelayer();
   ~EndpointRelayer() override;
 
-  Mutex mutex_;
+  util::Mutex mutex_;
   util::RefPtr<ChannelEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_);
   std::unique_ptr<Filter> filter_ MOJO_GUARDED_BY(mutex_);
 
diff --git a/mojo/edk/system/incoming_endpoint.cc b/mojo/edk/system/incoming_endpoint.cc
index 32549b1..d1d5715 100644
--- a/mojo/edk/system/incoming_endpoint.cc
+++ b/mojo/edk/system/incoming_endpoint.cc
@@ -14,6 +14,7 @@
 #include "mojo/edk/system/remote_producer_data_pipe_impl.h"
 
 using mojo::util::MakeRefCounted;
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/incoming_endpoint.h b/mojo/edk/system/incoming_endpoint.h
index 02bf0b4..1ad708e 100644
--- a/mojo/edk/system/incoming_endpoint.h
+++ b/mojo/edk/system/incoming_endpoint.h
@@ -9,8 +9,9 @@
 
 #include "mojo/edk/system/channel_endpoint_client.h"
 #include "mojo/edk/system/message_in_transit_queue.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 struct MojoCreateDataPipeOptions;
@@ -53,7 +54,7 @@
   IncomingEndpoint();
   ~IncomingEndpoint() override;
 
-  Mutex mutex_;
+  util::Mutex mutex_;
   util::RefPtr<ChannelEndpoint> endpoint_ MOJO_GUARDED_BY(mutex_);
   MessageInTransitQueue message_queue_ MOJO_GUARDED_BY(mutex_);
 
diff --git a/mojo/edk/system/master_connection_manager.cc b/mojo/edk/system/master_connection_manager.cc
index 4f2e555..84f838a 100644
--- a/mojo/edk/system/master_connection_manager.cc
+++ b/mojo/edk/system/master_connection_manager.cc
@@ -25,6 +25,8 @@
 #include "mojo/edk/util/make_unique.h"
 #include "mojo/public/cpp/system/macros.h"
 
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 
diff --git a/mojo/edk/system/master_connection_manager.h b/mojo/edk/system/master_connection_manager.h
index 81ce662..e751e4d 100644
--- a/mojo/edk/system/master_connection_manager.h
+++ b/mojo/edk/system/master_connection_manager.h
@@ -13,7 +13,8 @@
 #include "mojo/edk/embedder/platform_task_runner.h"
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/edk/system/connection_manager.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace base {
@@ -147,7 +148,7 @@
 
   // Note: |mutex_| is not needed in the constructor, |Init()|,
   // |Shutdown()|/|ShutdownOnPrivateThread()|, or the destructor
-  Mutex mutex_;
+  util::Mutex mutex_;
 
   ProcessIdentifier next_process_identifier_ MOJO_GUARDED_BY(mutex_);
 
diff --git a/mojo/edk/system/message_pipe.cc b/mojo/edk/system/message_pipe.cc
index 2337aea..5256bd3 100644
--- a/mojo/edk/system/message_pipe.cc
+++ b/mojo/edk/system/message_pipe.cc
@@ -20,6 +20,7 @@
 #include "mojo/edk/util/make_unique.h"
 
 using mojo::util::MakeRefCounted;
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/message_pipe.h b/mojo/edk/system/message_pipe.h
index 2d161e1..99b1200 100644
--- a/mojo/edk/system/message_pipe.h
+++ b/mojo/edk/system/message_pipe.h
@@ -18,8 +18,9 @@
 #include "mojo/edk/system/memory.h"
 #include "mojo/edk/system/message_in_transit.h"
 #include "mojo/edk/system/message_pipe_endpoint.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/message_pipe.h"
 #include "mojo/public/c/system/types.h"
 #include "mojo/public/cpp/system/macros.h"
@@ -137,7 +138,7 @@
       std::vector<DispatcherTransport>* transports)
       MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
 
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
   std::unique_ptr<MessagePipeEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_);
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipe);
diff --git a/mojo/edk/system/message_pipe_dispatcher.h b/mojo/edk/system/message_pipe_dispatcher.h
index c324178..da64649 100644
--- a/mojo/edk/system/message_pipe_dispatcher.h
+++ b/mojo/edk/system/message_pipe_dispatcher.h
@@ -8,6 +8,7 @@
 #include "mojo/edk/system/dispatcher.h"
 #include "mojo/edk/system/memory.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/mutex.cc b/mojo/edk/system/mutex.cc
deleted file mode 100644
index 45f4389..0000000
--- a/mojo/edk/system/mutex.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/edk/system/mutex.h"
-
-#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
-#include <errno.h>
-#include <string.h>
-
-#include "base/logging.h"
-
-namespace mojo {
-namespace system {
-
-Mutex::Mutex() {
-  pthread_mutexattr_t attr;
-  int error = pthread_mutexattr_init(&attr);
-  DCHECK(!error) << "pthread_mutexattr_init: " << strerror(error);
-  error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
-  DCHECK(!error) << "pthread_mutexattr_settype: " << strerror(error);
-  error = pthread_mutex_init(&impl_, &attr);
-  DCHECK(!error) << "pthread_mutex_init: " << strerror(error);
-  error = pthread_mutexattr_destroy(&attr);
-  DCHECK(!error) << "pthread_mutexattr_destroy: " << strerror(error);
-}
-
-Mutex::~Mutex() {
-  int error = pthread_mutex_destroy(&impl_);
-  DCHECK(!error) << "pthread_mutex_destroy: " << strerror(error);
-}
-
-void Mutex::Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() {
-  int error = pthread_mutex_lock(&impl_);
-  DCHECK(!error) << "pthread_mutex_lock: " << strerror(error);
-}
-
-void Mutex::Unlock() MOJO_UNLOCK_FUNCTION() {
-  int error = pthread_mutex_unlock(&impl_);
-  DCHECK(!error) << "pthread_mutex_unlock: " << strerror(error);
-}
-
-bool Mutex::TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
-  int error = pthread_mutex_trylock(&impl_);
-  DCHECK(!error || error == EBUSY) << "pthread_mutex_trylock: "
-                                   << strerror(error);
-  return !error;
-}
-
-void Mutex::AssertHeld() MOJO_ASSERT_EXCLUSIVE_LOCK() {
-  int error = pthread_mutex_lock(&impl_);
-  DCHECK_EQ(error, EDEADLK) << ". pthread_mutex_lock: " << strerror(error);
-}
-
-}  // namespace system
-}  // namespace mojo
-
-#endif  // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
diff --git a/mojo/edk/system/platform_handle_dispatcher.cc b/mojo/edk/system/platform_handle_dispatcher.cc
index f1f850e..91c64fd 100644
--- a/mojo/edk/system/platform_handle_dispatcher.cc
+++ b/mojo/edk/system/platform_handle_dispatcher.cc
@@ -8,6 +8,7 @@
 
 #include "base/logging.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/platform_handle_dispatcher.h b/mojo/edk/system/platform_handle_dispatcher.h
index d9baaa6..d9b809f 100644
--- a/mojo/edk/system/platform_handle_dispatcher.h
+++ b/mojo/edk/system/platform_handle_dispatcher.h
@@ -8,6 +8,7 @@
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/edk/system/simple_dispatcher.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/raw_channel.cc b/mojo/edk/system/raw_channel.cc
index 9c1aa24..16f924d 100644
--- a/mojo/edk/system/raw_channel.cc
+++ b/mojo/edk/system/raw_channel.cc
@@ -16,6 +16,8 @@
 #include "mojo/edk/system/message_in_transit.h"
 #include "mojo/edk/system/transport_data.h"
 
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 
diff --git a/mojo/edk/system/raw_channel.h b/mojo/edk/system/raw_channel.h
index 6a78395..beb0194 100644
--- a/mojo/edk/system/raw_channel.h
+++ b/mojo/edk/system/raw_channel.h
@@ -13,8 +13,8 @@
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/edk/system/message_in_transit.h"
 #include "mojo/edk/system/message_in_transit_queue.h"
-#include "mojo/edk/system/mutex.h"
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/mutex.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace base {
@@ -211,7 +211,9 @@
                         size_t bytes_written) MOJO_LOCKS_EXCLUDED(write_mutex_);
 
   base::MessageLoopForIO* message_loop_for_io() { return message_loop_for_io_; }
-  Mutex& write_mutex() MOJO_LOCK_RETURNED(write_mutex_) { return write_mutex_; }
+  util::Mutex& write_mutex() MOJO_LOCK_RETURNED(write_mutex_) {
+    return write_mutex_;
+  }
 
   // Should only be called on the I/O thread.
   ReadBuffer* read_buffer() { return read_buffer_.get(); }
@@ -319,7 +321,7 @@
   bool* set_on_shutdown_;
   std::unique_ptr<ReadBuffer> read_buffer_;
 
-  Mutex write_mutex_;  // Protects the following members.
+  util::Mutex write_mutex_;  // Protects the following members.
   bool write_stopped_ MOJO_GUARDED_BY(write_mutex_);
   std::unique_ptr<WriteBuffer> write_buffer_ MOJO_GUARDED_BY(write_mutex_);
 
diff --git a/mojo/edk/system/raw_channel_posix.cc b/mojo/edk/system/raw_channel_posix.cc
index dbf122d..096d0d7 100644
--- a/mojo/edk/system/raw_channel_posix.cc
+++ b/mojo/edk/system/raw_channel_posix.cc
@@ -25,6 +25,8 @@
 #include "mojo/edk/util/make_unique.h"
 #include "mojo/public/cpp/system/macros.h"
 
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 
diff --git a/mojo/edk/system/raw_channel_unittest.cc b/mojo/edk/system/raw_channel_unittest.cc
index afcf771..0c18226 100644
--- a/mojo/edk/system/raw_channel_unittest.cc
+++ b/mojo/edk/system/raw_channel_unittest.cc
@@ -17,7 +17,6 @@
 #include "mojo/edk/embedder/platform_handle.h"
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/edk/system/message_in_transit.h"
-#include "mojo/edk/system/mutex.h"
 #include "mojo/edk/system/test/random.h"
 #include "mojo/edk/system/test/scoped_test_dir.h"
 #include "mojo/edk/system/test/simple_test_thread.h"
@@ -27,10 +26,14 @@
 #include "mojo/edk/system/waitable_event.h"
 #include "mojo/edk/test/test_utils.h"
 #include "mojo/edk/util/make_unique.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/scoped_file.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+using mojo::util::Mutex;
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 namespace {
diff --git a/mojo/edk/system/shared_buffer_dispatcher.h b/mojo/edk/system/shared_buffer_dispatcher.h
index 9c22606..9f153cf 100644
--- a/mojo/edk/system/shared_buffer_dispatcher.h
+++ b/mojo/edk/system/shared_buffer_dispatcher.h
@@ -11,6 +11,7 @@
 #include "mojo/edk/system/memory.h"
 #include "mojo/edk/system/simple_dispatcher.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/simple_dispatcher.h b/mojo/edk/system/simple_dispatcher.h
index b44b020..c305d5f 100644
--- a/mojo/edk/system/simple_dispatcher.h
+++ b/mojo/edk/system/simple_dispatcher.h
@@ -9,6 +9,7 @@
 
 #include "mojo/edk/system/awakable_list.h"
 #include "mojo/edk/system/dispatcher.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
diff --git a/mojo/edk/system/simple_dispatcher_unittest.cc b/mojo/edk/system/simple_dispatcher_unittest.cc
index 6fb42f6..998801b 100644
--- a/mojo/edk/system/simple_dispatcher_unittest.cc
+++ b/mojo/edk/system/simple_dispatcher_unittest.cc
@@ -16,15 +16,16 @@
 #include "mojo/edk/system/test/sleep.h"
 #include "mojo/edk/system/test/stopwatch.h"
 #include "mojo/edk/system/test/timeouts.h"
-#include "mojo/edk/system/thread_annotations.h"
 #include "mojo/edk/system/waiter.h"
 #include "mojo/edk/system/waiter_test_utils.h"
 #include "mojo/edk/util/make_unique.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 using mojo::util::MakeRefCounted;
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/slave_connection_manager.cc b/mojo/edk/system/slave_connection_manager.cc
index 9780735..749597a 100644
--- a/mojo/edk/system/slave_connection_manager.cc
+++ b/mojo/edk/system/slave_connection_manager.cc
@@ -13,6 +13,8 @@
 #include "mojo/edk/system/message_in_transit.h"
 #include "mojo/edk/util/make_unique.h"
 
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 
diff --git a/mojo/edk/system/slave_connection_manager.h b/mojo/edk/system/slave_connection_manager.h
index 86876bb..bd66534 100644
--- a/mojo/edk/system/slave_connection_manager.h
+++ b/mojo/edk/system/slave_connection_manager.h
@@ -13,9 +13,9 @@
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/edk/embedder/slave_process_delegate.h"
 #include "mojo/edk/system/connection_manager.h"
-#include "mojo/edk/system/mutex.h"
 #include "mojo/edk/system/raw_channel.h"
 #include "mojo/edk/system/waitable_event.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace base {
@@ -146,7 +146,7 @@
   //
   // TODO(vtl): This is all a hack. It'd really suffice to have a version of
   // |RawChannel| with fully synchronous reading and writing.
-  Mutex mutex_;
+  util::Mutex mutex_;
   AutoResetWaitableEvent event_;
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(SlaveConnectionManager);
diff --git a/mojo/edk/system/test_channel_endpoint_client.cc b/mojo/edk/system/test_channel_endpoint_client.cc
index 2ab9457..cc7b25d 100644
--- a/mojo/edk/system/test_channel_endpoint_client.cc
+++ b/mojo/edk/system/test_channel_endpoint_client.cc
@@ -10,6 +10,7 @@
 #include "mojo/edk/system/waitable_event.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+using mojo::util::MutexLocker;
 using mojo::util::RefPtr;
 
 namespace mojo {
diff --git a/mojo/edk/system/test_channel_endpoint_client.h b/mojo/edk/system/test_channel_endpoint_client.h
index df04460..420d0b8 100644
--- a/mojo/edk/system/test_channel_endpoint_client.h
+++ b/mojo/edk/system/test_channel_endpoint_client.h
@@ -10,8 +10,9 @@
 #include "mojo/edk/system/channel_endpoint.h"
 #include "mojo/edk/system/channel_endpoint_client.h"
 #include "mojo/edk/system/message_in_transit_queue.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/edk/util/ref_ptr.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
@@ -52,7 +53,7 @@
   TestChannelEndpointClient();
   ~TestChannelEndpointClient() override;
 
-  mutable Mutex mutex_;
+  mutable util::Mutex mutex_;
 
   unsigned port_ MOJO_GUARDED_BY(mutex_);
   util::RefPtr<ChannelEndpoint> endpoint_ MOJO_GUARDED_BY(mutex_);
diff --git a/mojo/edk/system/waitable_event.cc b/mojo/edk/system/waitable_event.cc
index 2a08fc3..c05d038 100644
--- a/mojo/edk/system/waitable_event.cc
+++ b/mojo/edk/system/waitable_event.cc
@@ -7,6 +7,10 @@
 #include "base/logging.h"
 #include "base/time/time.h"
 
+using mojo::util::CondVar;
+using mojo::util::Mutex;
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 
diff --git a/mojo/edk/system/waitable_event.h b/mojo/edk/system/waitable_event.h
index a9362b1..38c75e0 100644
--- a/mojo/edk/system/waitable_event.h
+++ b/mojo/edk/system/waitable_event.h
@@ -10,9 +10,9 @@
 #ifndef MOJO_EDK_SYSTEM_WAITABLE_EVENT_H_
 #define MOJO_EDK_SYSTEM_WAITABLE_EVENT_H_
 
-#include "mojo/edk/system/cond_var.h"
-#include "mojo/edk/system/mutex.h"
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/cond_var.h"
+#include "mojo/edk/util/mutex.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
@@ -62,8 +62,8 @@
   bool IsSignaledForTest();
 
  private:
-  CondVar cv_;
-  Mutex mutex_;
+  util::CondVar cv_;
+  util::Mutex mutex_;
 
   // True if this event is in the signaled state.
   bool signaled_ MOJO_GUARDED_BY(mutex_) = false;
@@ -104,8 +104,8 @@
   bool IsSignaledForTest();
 
  private:
-  CondVar cv_;
-  Mutex mutex_;
+  util::CondVar cv_;
+  util::Mutex mutex_;
 
   // True if this event is in the signaled state.
   bool signaled_ MOJO_GUARDED_BY(mutex_) = false;
diff --git a/mojo/edk/system/waiter.cc b/mojo/edk/system/waiter.cc
index 2018f7e..540dcb6 100644
--- a/mojo/edk/system/waiter.cc
+++ b/mojo/edk/system/waiter.cc
@@ -7,6 +7,8 @@
 #include "base/logging.h"
 #include "base/time/time.h"
 
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 
diff --git a/mojo/edk/system/waiter.h b/mojo/edk/system/waiter.h
index 39c28d9..0a2f7ee 100644
--- a/mojo/edk/system/waiter.h
+++ b/mojo/edk/system/waiter.h
@@ -8,9 +8,9 @@
 #include <stdint.h>
 
 #include "mojo/edk/system/awakable.h"
-#include "mojo/edk/system/cond_var.h"
-#include "mojo/edk/system/mutex.h"
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/cond_var.h"
+#include "mojo/edk/util/mutex.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/c/system/types.h"
 #include "mojo/public/cpp/system/macros.h"
 
@@ -61,8 +61,8 @@
   bool Awake(MojoResult result, uintptr_t context) override;
 
  private:
-  CondVar cv_;  // Associated to |mutex_|.
-  Mutex mutex_;
+  util::CondVar cv_;  // Associated to |mutex_|.
+  util::Mutex mutex_;
 #ifndef NDEBUG
   bool initialized_ MOJO_GUARDED_BY(mutex_);
 #endif
diff --git a/mojo/edk/system/waiter_unittest.cc b/mojo/edk/system/waiter_unittest.cc
index faf89f8..9a344f5 100644
--- a/mojo/edk/system/waiter_unittest.cc
+++ b/mojo/edk/system/waiter_unittest.cc
@@ -11,14 +11,17 @@
 
 #include <stdint.h>
 
-#include "mojo/edk/system/mutex.h"
 #include "mojo/edk/system/test/simple_test_thread.h"
 #include "mojo/edk/system/test/sleep.h"
 #include "mojo/edk/system/test/stopwatch.h"
 #include "mojo/edk/system/test/timeouts.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+using mojo::util::Mutex;
+using mojo::util::MutexLocker;
+
 namespace mojo {
 namespace system {
 namespace {
diff --git a/mojo/edk/test/multiprocess_test_helper.cc b/mojo/edk/test/multiprocess_test_helper.cc
index 81fbdcc..65265a3 100644
--- a/mojo/edk/test/multiprocess_test_helper.cc
+++ b/mojo/edk/test/multiprocess_test_helper.cc
@@ -6,6 +6,7 @@
 
 #include "base/command_line.h"
 #include "base/logging.h"
+#include "base/test/test_timeouts.h"
 #include "mojo/edk/embedder/platform_channel_pair.h"
 
 namespace mojo {
diff --git a/mojo/edk/test/multiprocess_test_helper.h b/mojo/edk/test/multiprocess_test_helper.h
index 2d02796..952df04 100644
--- a/mojo/edk/test/multiprocess_test_helper.h
+++ b/mojo/edk/test/multiprocess_test_helper.h
@@ -10,7 +10,6 @@
 
 #include "base/process/process.h"
 #include "base/test/multiprocess_test.h"
-#include "base/test/test_timeouts.h"
 #include "mojo/edk/embedder/scoped_platform_handle.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/multiprocess_func_list.h"
diff --git a/mojo/edk/util/BUILD.gn b/mojo/edk/util/BUILD.gn
index 775e1a6..6b30583 100644
--- a/mojo/edk/util/BUILD.gn
+++ b/mojo/edk/util/BUILD.gn
@@ -6,12 +6,19 @@
 
 mojo_edk_source_set("util") {
   sources = [
+    "cond_var.cc",
+    "cond_var.h",
+    "logging_internal.cc",
+    "logging_internal.h",
     "make_unique.h",
+    "mutex.cc",
+    "mutex.h",
     "ref_counted.h",
     "ref_counted_internal.h",
     "ref_ptr.h",
     "ref_ptr_internal.h",
     "scoped_file.h",
+    "thread_annotations.h",
   ]
 
   mojo_edk_configs = [ "mojo/edk/system:system_config" ]
@@ -24,15 +31,20 @@
   mojo_edk_visibility = [ "mojo/edk/system:mojo_system_unittests" ]
 
   sources = [
+    "cond_var_unittest.cc",
+    "mutex_unittest.cc",
     "ref_counted_unittest.cc",
+    "thread_annotations_unittest.cc",
   ]
 
-  mojo_sdk_deps = [ "mojo/public/cpp/system" ]
-
   deps = [
     ":util",
     "//testing/gtest",
   ]
+
+  mojo_sdk_deps = [ "mojo/public/cpp/system" ]
+
+  mojo_edk_deps = [ "mojo/edk/system/test" ]
 }
 
 mojo_edk_source_set("perftests") {
diff --git a/mojo/edk/system/cond_var.cc b/mojo/edk/util/cond_var.cc
similarity index 74%
rename from mojo/edk/system/cond_var.cc
rename to mojo/edk/util/cond_var.cc
index a80f83a..b675bf0 100644
--- a/mojo/edk/system/cond_var.cc
+++ b/mojo/edk/util/cond_var.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "mojo/edk/system/cond_var.h"
+#include "mojo/edk/util/cond_var.h"
 
 #include <errno.h>
 #include <string.h>
@@ -10,12 +10,12 @@
 
 #include <limits>
 
-#include "base/logging.h"
 #include "build/build_config.h"
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/logging_internal.h"
+#include "mojo/edk/util/mutex.h"
 
 namespace mojo {
-namespace system {
+namespace util {
 
 namespace {
 
@@ -27,8 +27,8 @@
 #if defined(OS_MACOSX)
   int error = pthread_cond_timedwait_relative_np(posix_cond_var, posix_mutex,
                                                  &timeout_rel);
-  DCHECK(error == 0 || error == ETIMEDOUT || error == EINTR)
-      << ". pthread_cond_timedwait_relative_np: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(error == 0 || error == ETIMEDOUT || error == EINTR,
+                             "pthread_cond_timedwait_relative_np", error);
   return error == ETIMEDOUT;
 #else
   static const long kNanosecondsPerSecond = 1000000000L;
@@ -45,15 +45,15 @@
   struct timespec timeout_abs;
   int error = clock_gettime(kClockType, &timeout_abs);
   // Note: The return value of |clock_gettime()| is *not* an error code, unlike
-  // the pthreads functions.
-  DPCHECK(!error) << "clock_gettime";
+  // the pthreads functions (however, it sets errno).
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "clock_gettime", errno);
 
   timeout_abs.tv_sec += timeout_rel.tv_sec;
   timeout_abs.tv_nsec += timeout_rel.tv_nsec;
   if (timeout_abs.tv_nsec >= kNanosecondsPerSecond) {
     timeout_abs.tv_sec++;
     timeout_abs.tv_nsec -= kNanosecondsPerSecond;
-    DCHECK_LT(timeout_abs.tv_nsec, kNanosecondsPerSecond);
+    INTERNAL_DCHECK(timeout_abs.tv_nsec < kNanosecondsPerSecond);
   }
 
 // Older Android doesn't have |pthread_condattr_setclock()|, but they have
@@ -61,12 +61,12 @@
 #if defined(OS_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC)
   error = pthread_cond_timedwait_monotonic_np(posix_cond_var, posix_mutex,
                                               &timeout_abs);
-  DCHECK(error == 0 || error == ETIMEDOUT || error == EINTR)
-      << ". pthread_cond_timedwait_monotonic_np: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(error == 0 || error == ETIMEDOUT || error == EINTR,
+                             "pthread_cond_timedwait_monotonic_np", error);
 #else
   error = pthread_cond_timedwait(posix_cond_var, posix_mutex, &timeout_abs);
-  DCHECK(error == 0 || error == ETIMEDOUT || error == EINTR)
-      << ". pthread_cond_timedwait: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(error == 0 || error == ETIMEDOUT || error == EINTR,
+                             "pthread_cond_timedwait", error);
 #endif  // defined(OS_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC)
   return error == ETIMEDOUT;
 #endif  // defined(OS_MACOSX)
@@ -81,30 +81,30 @@
     !(defined(OS_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
   pthread_condattr_t attr;
   int error = pthread_condattr_init(&attr);
-  DCHECK(!error) << "pthread_condattr_init: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_condattr_init", error);
   error = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
-  DCHECK(!error) << "pthread_condattr_setclock: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_condattr_setclock", error);
   error = pthread_cond_init(&impl_, &attr);
-  DCHECK(!error) << "pthread_cond_init: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_cond_init", error);
   error = pthread_condattr_destroy(&attr);
-  DCHECK(!error) << "pthread_condattr_destroy: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_condattr_destroy", error);
 #else
   int error = pthread_cond_init(&impl_, nullptr);
-  DCHECK(!error) << "pthread_cond_init: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_cond_init", error);
 #endif  // !defined(OS_MACOSX) && !defined(OS_NACL) && !(defined(OS_ANDROID)...)
 }
 
 CondVar::~CondVar() {
   int error = pthread_cond_destroy(&impl_);
-  DCHECK(!error) << "pthread_cond_destroy: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_cond_destroy", error);
 }
 
 void CondVar::Wait(Mutex* mutex) {
-  DCHECK(mutex);
+  INTERNAL_DCHECK(mutex);
   mutex->AssertHeld();
 
   int error = pthread_cond_wait(&impl_, &mutex->impl_);
-  DCHECK(!error) << "pthread_cond_wait: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_cond_wait", error);
 }
 
 bool CondVar::WaitWithTimeout(Mutex* mutex, uint64_t timeout_microseconds) {
@@ -122,7 +122,7 @@
     return false;  // Did *not* time out.
   }
 
-  DCHECK(mutex);
+  INTERNAL_DCHECK(mutex);
   mutex->AssertHeld();
 
   struct timespec timeout_rel = {};
@@ -135,13 +135,13 @@
 
 void CondVar::Signal() {
   int error = pthread_cond_signal(&impl_);
-  DCHECK(!error) << "pthread_cond_signal: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_cond_signal", error);
 }
 
 void CondVar::SignalAll() {
   int error = pthread_cond_broadcast(&impl_);
-  DCHECK(!error) << "pthread_cond_broadcast: " << strerror(error);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_cond_broadcast", error);
 }
 
-}  // namespace system
+}  // namespace util
 }  // namespace mojo
diff --git a/mojo/edk/system/cond_var.h b/mojo/edk/util/cond_var.h
similarity index 87%
rename from mojo/edk/system/cond_var.h
rename to mojo/edk/util/cond_var.h
index 1d04972..68b0fdd 100644
--- a/mojo/edk/system/cond_var.h
+++ b/mojo/edk/util/cond_var.h
@@ -2,19 +2,19 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// A condition variable class (to be used with |mojo::system::Mutex|).
+// A condition variable class (to be used with |mojo::util::Mutex|).
 
-#ifndef MOJO_EDK_SYSTEM_COND_VAR_H_
-#define MOJO_EDK_SYSTEM_COND_VAR_H_
+#ifndef MOJO_EDK_UTIL_COND_VAR_H_
+#define MOJO_EDK_UTIL_COND_VAR_H_
 
 #include <pthread.h>
 #include <stdint.h>
 
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
-namespace system {
+namespace util {
 
 class Mutex;
 
@@ -60,7 +60,7 @@
   MOJO_DISALLOW_COPY_AND_ASSIGN(CondVar);
 };
 
-}  // namespace system
+}  // namespace util
 }  // namespace mojo
 
-#endif  // MOJO_EDK_SYSTEM_COND_VAR_H_
+#endif  // MOJO_EDK_UTIL_COND_VAR_H_
diff --git a/mojo/edk/system/cond_var_unittest.cc b/mojo/edk/util/cond_var_unittest.cc
similarity index 85%
rename from mojo/edk/system/cond_var_unittest.cc
rename to mojo/edk/util/cond_var_unittest.cc
index 568da83..930765b 100644
--- a/mojo/edk/system/cond_var_unittest.cc
+++ b/mojo/edk/util/cond_var_unittest.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "mojo/edk/system/cond_var.h"
+#include "mojo/edk/util/cond_var.h"
 
 #include <stdint.h>
 #include <stdlib.h>
@@ -11,20 +11,20 @@
 #include <type_traits>
 #include <vector>
 
-#include "mojo/edk/system/mutex.h"
 #include "mojo/edk/system/test/sleep.h"
 #include "mojo/edk/system/test/stopwatch.h"
 #include "mojo/edk/system/test/timeouts.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace mojo {
-namespace system {
+namespace util {
 namespace {
 
 // Sleeps for a "very small" amount of time.
 void EpsilonRandomSleep() {
-  test::SleepMilliseconds(static_cast<unsigned>(rand()) % 20u);
+  system::test::SleepMilliseconds(static_cast<unsigned>(rand()) % 20u);
 }
 
 // We'll use |MojoDeadline| with |uint64_t| (for |CondVar::WaitWithTimeout()|'s
@@ -56,7 +56,8 @@
     // happen if we're interrupted, e.g., by ^Z.)
     EXPECT_TRUE(cv.WaitWithTimeout(&mu, 0));
     mu.AssertHeld();
-    EXPECT_TRUE(cv.WaitWithTimeout(&mu, test::DeadlineFromMilliseconds(1)));
+    EXPECT_TRUE(
+        cv.WaitWithTimeout(&mu, system::test::DeadlineFromMilliseconds(1)));
     mu.AssertHeld();
   }
 
@@ -88,7 +89,7 @@
       }
     } else {
       while (!condition) {
-        EXPECT_FALSE(cv.WaitWithTimeout(&mu, test::TinyTimeout()));
+        EXPECT_FALSE(cv.WaitWithTimeout(&mu, system::test::TinyTimeout()));
         mu.AssertHeld();
       }
     }
@@ -117,7 +118,8 @@
             }
           } else {
             while (!condition) {
-              EXPECT_FALSE(cv.WaitWithTimeout(&mu, test::TinyTimeout()));
+              EXPECT_FALSE(
+                  cv.WaitWithTimeout(&mu, system::test::TinyTimeout()));
               mu.AssertHeld();
             }
           }
@@ -141,7 +143,7 @@
 TEST(CondVarTest, Timeouts) {
   static const unsigned kTestTimeoutsMs[] = {0, 10, 20, 40, 80, 160};
 
-  test::Stopwatch stopwatch;
+  system::test::Stopwatch stopwatch;
 
   Mutex mu;
   CondVar cv;
@@ -149,7 +151,8 @@
   MutexLocker locker(&mu);
 
   for (size_t i = 0; i < MOJO_ARRAYSIZE(kTestTimeoutsMs); i++) {
-    uint64_t timeout = test::DeadlineFromMilliseconds(kTestTimeoutsMs[i]);
+    uint64_t timeout =
+        system::test::DeadlineFromMilliseconds(kTestTimeoutsMs[i]);
 
     stopwatch.Start();
     // See note in CondVarTest.Basic about spurious wakeups.
@@ -159,12 +162,12 @@
     // It should time out after *at least* the specified amount of time.
     EXPECT_GE(elapsed, timeout);
     // But we expect that it should time out soon after that amount of time.
-    EXPECT_LT(elapsed, timeout + test::EpsilonTimeout());
+    EXPECT_LT(elapsed, timeout + system::test::EpsilonTimeout());
   }
 }
 
 // TODO(vtl): Test that |Signal()| (usually) wakes only one waiter.
 
 }  // namespace
-}  // namespace system
+}  // namespace util
 }  // namespace mojo
diff --git a/mojo/edk/util/logging_internal.cc b/mojo/edk/util/logging_internal.cc
new file mode 100644
index 0000000..c24e4dc
--- /dev/null
+++ b/mojo/edk/util/logging_internal.cc
@@ -0,0 +1,33 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/edk/util/mutex.h"
+
+#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+namespace mojo {
+namespace util {
+namespace internal {
+
+void DcheckHelper(const char* file, int line, const char* condition_string) {
+  fprintf(stderr, "%s:%d: Check failed: %s\n", file, line, condition_string);
+  abort();
+}
+
+void DcheckWithErrnoHelper(const char* file,
+                           int line,
+                           const char* fn,
+                           int error) {
+  fprintf(stderr, "%s:%d: %s: %s\n", file, line, fn, strerror(error));
+  abort();
+}
+
+}  // namespace internal
+}  // namespace util
+}  // namespace mojo
+
+#endif  // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
diff --git a/mojo/edk/util/logging_internal.h b/mojo/edk/util/logging_internal.h
new file mode 100644
index 0000000..59e501e
--- /dev/null
+++ b/mojo/edk/util/logging_internal.h
@@ -0,0 +1,61 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Internal logging macros, to avoid external dependencies.
+
+#ifndef MOJO_EDK_UTIL_LOGGING_INTERNAL_H_
+#define MOJO_EDK_UTIL_LOGGING_INTERNAL_H_
+
+#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
+
+#define INTERNAL_DCHECK(condition) \
+  do {                             \
+  } while (false && (condition))
+
+#define INTERNAL_DCHECK_WITH_ERRNO(condition, fn, error) \
+  do {                                                   \
+  } while (false && (condition) && (error))
+
+#else
+
+// Our own simplified "DCHECK". Asserts that |condition| is true. If not, "logs"
+// the failing condition and aborts.
+#define INTERNAL_DCHECK(condition)                                          \
+  do {                                                                      \
+    if (!(condition)) {                                                     \
+      ::mojo::util::internal::DcheckHelper(__FILE__, __LINE__, #condition); \
+    }                                                                       \
+  } while (false)
+
+// Our own simplified "DCHECK"/"DPCHECK" hybrid. Asserts that |condition| is
+// true. If not, "logs" |fn| with errno value |error| and aborts. (This doesn't
+// just use |errno| since some APIs, like pthreads, don't set errno.)
+#define INTERNAL_DCHECK_WITH_ERRNO(condition, fn, error)                    \
+  do {                                                                      \
+    if (!(condition)) {                                                     \
+      ::mojo::util::internal::DcheckWithErrnoHelper(__FILE__, __LINE__, fn, \
+                                                    error);                 \
+    }                                                                       \
+  } while (false)
+
+namespace mojo {
+namespace util {
+namespace internal {
+
+// Helper for |INTERNAL_DCHECK_WITH_ERRNO()| above.
+void DcheckHelper(const char* file, int line, const char* condition_string);
+
+// Helper for |INTERNAL_DCHECK_WITH_ERRNO()| above.
+void DcheckWithErrnoHelper(const char* file,
+                           int line,
+                           const char* fn,
+                           int error);
+
+}  // namespace internal
+}  // namespace util
+}  // namespace mojo
+
+#endif  // defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
+
+#endif  // MOJO_EDK_UTIL_LOGGING_INTERNAL_H_
diff --git a/mojo/edk/util/mutex.cc b/mojo/edk/util/mutex.cc
new file mode 100644
index 0000000..1f006df
--- /dev/null
+++ b/mojo/edk/util/mutex.cc
@@ -0,0 +1,57 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/edk/util/mutex.h"
+
+#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+#include <errno.h>
+
+#include "mojo/edk/util/logging_internal.h"
+
+namespace mojo {
+namespace util {
+
+Mutex::Mutex() {
+  pthread_mutexattr_t attr;
+  int error = pthread_mutexattr_init(&attr);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutexattr_init", error);
+  error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutexattr_settype", error);
+  error = pthread_mutex_init(&impl_, &attr);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutex_init", error);
+  error = pthread_mutexattr_destroy(&attr);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutexattr_destroy", error);
+}
+
+Mutex::~Mutex() {
+  int error = pthread_mutex_destroy(&impl_);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutex_destroy", error);
+}
+
+void Mutex::Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() {
+  int error = pthread_mutex_lock(&impl_);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutex_lock", error);
+}
+
+void Mutex::Unlock() MOJO_UNLOCK_FUNCTION() {
+  int error = pthread_mutex_unlock(&impl_);
+  INTERNAL_DCHECK_WITH_ERRNO(!error, "pthread_mutex_unlock", error);
+}
+
+bool Mutex::TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
+  int error = pthread_mutex_trylock(&impl_);
+  INTERNAL_DCHECK_WITH_ERRNO(!error || error == EBUSY, "pthread_mutex_trylock",
+                             error);
+  return !error;
+}
+
+void Mutex::AssertHeld() MOJO_ASSERT_EXCLUSIVE_LOCK() {
+  int error = pthread_mutex_lock(&impl_);
+  INTERNAL_DCHECK_WITH_ERRNO(error == EDEADLK, "pthread_mutex_lock", error);
+}
+
+}  // namespace util
+}  // namespace mojo
+
+#endif  // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
diff --git a/mojo/edk/system/mutex.h b/mojo/edk/util/mutex.h
similarity index 89%
rename from mojo/edk/system/mutex.h
rename to mojo/edk/util/mutex.h
index 0ce1ed3..381ce7a 100644
--- a/mojo/edk/system/mutex.h
+++ b/mojo/edk/util/mutex.h
@@ -6,22 +6,21 @@
 //
 // TODO(vtl): Add support for non-exclusive (reader) locks.
 
-#ifndef MOJO_EDK_SYSTEM_MUTEX_H_
-#define MOJO_EDK_SYSTEM_MUTEX_H_
+#ifndef MOJO_EDK_UTIL_MUTEX_H_
+#define MOJO_EDK_UTIL_MUTEX_H_
 
 #include <pthread.h>
 
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/thread_annotations.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
-namespace system {
-
-// So |Mutex| can friend it.
-class CondVar;
+namespace util {
 
 // Mutex -----------------------------------------------------------------------
 
+class CondVar;
+
 class MOJO_LOCKABLE Mutex {
  public:
 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
@@ -78,7 +77,7 @@
   MOJO_DISALLOW_COPY_AND_ASSIGN(MutexLocker);
 };
 
-}  // namespace system
+}  // namespace util
 }  // namespace mojo
 
-#endif  // MOJO_EDK_SYSTEM_MUTEX_H_
+#endif  // MOJO_EDK_UTIL_MUTEX_H_
diff --git a/mojo/edk/system/mutex_unittest.cc b/mojo/edk/util/mutex_unittest.cc
similarity index 94%
rename from mojo/edk/system/mutex_unittest.cc
rename to mojo/edk/util/mutex_unittest.cc
index 33d26f9..6730aba 100644
--- a/mojo/edk/system/mutex_unittest.cc
+++ b/mojo/edk/util/mutex_unittest.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 
 #include <stdlib.h>
 
@@ -12,12 +12,12 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace mojo {
-namespace system {
+namespace util {
 namespace {
 
 // Sleeps for a "very small" amount of time.
 void EpsilonRandomSleep() {
-  test::SleepMilliseconds(static_cast<unsigned>(rand()) % 20u);
+  system::test::SleepMilliseconds(static_cast<unsigned>(rand()) % 20u);
 }
 
 // Basic test to make sure that Lock()/Unlock()/TryLock() don't crash ----------
@@ -93,7 +93,7 @@
   // For non-Debug builds, |AssertHeld()| should do nothing.
   mutex.AssertHeld();
 #else
-  EXPECT_DEATH_IF_SUPPORTED({ mutex.AssertHeld(); }, "Check failed");
+  EXPECT_DEATH_IF_SUPPORTED({ mutex.AssertHeld(); }, "pthread_mutex_lock");
 #endif  // defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
 
   // TODO(vtl): Should also test the case when the mutex is held by another
@@ -197,5 +197,5 @@
 }
 
 }  // namespace
-}  // namespace system
+}  // namespace util
 }  // namespace mojo
diff --git a/mojo/edk/system/thread_annotations.h b/mojo/edk/util/thread_annotations.h
similarity index 95%
rename from mojo/edk/system/thread_annotations.h
rename to mojo/edk/util/thread_annotations.h
index ffac558..0cc0e01 100644
--- a/mojo/edk/system/thread_annotations.h
+++ b/mojo/edk/util/thread_annotations.h
@@ -12,8 +12,8 @@
 // particular, |TRY_ACQUIRE()| doesn't work: b/19264527).
 // https://github.com/domokit/mojo/issues/314
 
-#ifndef MOJO_EDK_SYSTEM_THREAD_ANNOTATIONS_H_
-#define MOJO_EDK_SYSTEM_THREAD_ANNOTATIONS_H_
+#ifndef MOJO_EDK_UTIL_THREAD_ANNOTATIONS_H_
+#define MOJO_EDK_UTIL_THREAD_ANNOTATIONS_H_
 
 // Enable thread-safety attributes only with clang.
 // The attributes can be safely erased when compiling with other compilers.
@@ -82,4 +82,4 @@
 // implementations.
 #define MOJO_NOT_THREAD_SAFE MOJO_NO_THREAD_SAFETY_ANALYSIS
 
-#endif  // MOJO_EDK_SYSTEM_THREAD_ANNOTATIONS_H_
+#endif  // MOJO_EDK_UTIL_THREAD_ANNOTATIONS_H_
diff --git a/mojo/edk/system/thread_annotations_unittest.cc b/mojo/edk/util/thread_annotations_unittest.cc
similarity index 95%
rename from mojo/edk/system/thread_annotations_unittest.cc
rename to mojo/edk/util/thread_annotations_unittest.cc
index d56814f..838dda5 100644
--- a/mojo/edk/system/thread_annotations_unittest.cc
+++ b/mojo/edk/util/thread_annotations_unittest.cc
@@ -10,9 +10,9 @@
 // So instead we have some cheesy macros that you can define to enable
 // individual compilation failures.
 
-#include "mojo/edk/system/thread_annotations.h"
+#include "mojo/edk/util/thread_annotations.h"
 
-#include "mojo/edk/system/mutex.h"
+#include "mojo/edk/util/mutex.h"
 #include "mojo/public/cpp/system/macros.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -24,7 +24,7 @@
 // #define NC_ACQUIRED_BEFORE
 
 namespace mojo {
-namespace system {
+namespace util {
 namespace {
 
 // Test MOJO_GUARDED_BY --------------------------------------------------------
@@ -120,5 +120,5 @@
 // TODO(vtl): Test more things.
 
 }  // namespace
-}  // namespace system
+}  // namespace util
 }  // namespace mojo