Remove easy uses of //aos/mutex

I was hoping to get rid of it completely as one of the nontrivial users
of AOS_LOG, but need to write a compatible condition variable first.

Change-Id: I86c1c4084882bf789baabd0255e115d821154830
diff --git a/aos/logging/BUILD b/aos/logging/BUILD
index 45a9921..a9fcb14 100644
--- a/aos/logging/BUILD
+++ b/aos/logging/BUILD
@@ -23,10 +23,10 @@
         "//aos:macros",
         "//aos:thread_local",
         "//aos/libc:aos_strerror",
-        "//aos/mutex",
         "//aos/stl_mutex",
         "//aos/time",
         "//aos/type_traits",
+        "@com_github_google_glog//:glog",
         "@com_google_absl//absl/base",
     ],
 )
@@ -59,6 +59,7 @@
         ":implementations",
         ":logging",
         "//aos/testing:googletest",
+        "@com_github_google_glog//:glog",
     ],
 )
 
diff --git a/aos/logging/context.cc b/aos/logging/context.cc
index 0628e0e..0aa3e71 100644
--- a/aos/logging/context.cc
+++ b/aos/logging/context.cc
@@ -11,14 +11,15 @@
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <string>
 
-#include <errno.h>
-
 extern char *program_invocation_name;
 extern char *program_invocation_short_name;
 
+#include "glog/logging.h"
+
 #include "aos/complex_thread_local.h"
 #include "aos/die.h"
 #include "aos/logging/implementations.h"
diff --git a/aos/logging/implementations.h b/aos/logging/implementations.h
index 6395c37..bcce421 100644
--- a/aos/logging/implementations.h
+++ b/aos/logging/implementations.h
@@ -19,7 +19,6 @@
 #include "aos/logging/logging.h"
 #include "aos/logging/sizes.h"
 #include "aos/macros.h"
-#include "aos/mutex/mutex.h"
 #include "aos/time/time.h"
 #include "aos/type_traits/type_traits.h"
 
diff --git a/aos/logging/implementations_test.cc b/aos/logging/implementations_test.cc
index 058baab..6b85358 100644
--- a/aos/logging/implementations_test.cc
+++ b/aos/logging/implementations_test.cc
@@ -7,6 +7,8 @@
 
 #include "aos/logging/printf_formats.h"
 #include "aos/time/time.h"
+
+#include "glog/logging.h"
 #include "gtest/gtest.h"
 
 using ::testing::AssertionFailure;
diff --git a/aos/starter/BUILD b/aos/starter/BUILD
index 565a9cf..ae789b4 100644
--- a/aos/starter/BUILD
+++ b/aos/starter/BUILD
@@ -22,6 +22,7 @@
         "//aos/time",
         "//aos/util:run_command",
         "//third_party/libevent",
+        "@com_github_google_glog//:glog",
         "@com_google_absl//absl/base",
     ],
 )
diff --git a/aos/starter/starter.cc b/aos/starter/starter.cc
index fa0daae..c30a373 100644
--- a/aos/starter/starter.cc
+++ b/aos/starter/starter.cc
@@ -27,6 +27,8 @@
 #include <memory>
 #include <set>
 
+#include "absl/base/call_once.h"
+#include "glog/logging.h"
 #include "third_party/libevent/event.h"
 
 #include "aos/libc/aos_strsignal.h"
@@ -36,7 +38,6 @@
 #include "aos/unique_malloc_ptr.h"
 #include "aos/util/run_command.h"
 #include "aos/init.h"
-#include "absl/base/call_once.h"
 
 // This is the main piece of code that starts all of the rest of the code and
 // restarts it when the binaries are modified.
diff --git a/aos/testing/BUILD b/aos/testing/BUILD
index e70b5a4..1fd5380 100644
--- a/aos/testing/BUILD
+++ b/aos/testing/BUILD
@@ -26,7 +26,7 @@
         ":googletest",
         "//aos:thread_local",
         "//aos/logging:implementations",
-        "//aos/mutex",
+        "//aos/stl_mutex",
         "@com_google_absl//absl/base",
     ],
 )
diff --git a/aos/testing/test_logging.cc b/aos/testing/test_logging.cc
index b5b71ff..6024a80 100644
--- a/aos/testing/test_logging.cc
+++ b/aos/testing/test_logging.cc
@@ -9,7 +9,7 @@
 #include "absl/base/call_once.h"
 
 #include "aos/logging/implementations.h"
-#include "aos/mutex/mutex.h"
+#include "aos/stl_mutex/stl_mutex.h"
 #include "aos/thread_local.h"
 
 using ::aos::logging::LogMessage;
@@ -36,13 +36,13 @@
 
   // Clears out all of the messages already recorded.
   void ClearMessages() {
-    ::aos::MutexLocker locker(&messages_mutex_);
+    std::unique_lock<aos::stl_mutex> locker(messages_mutex_);
     messages_.clear();
   }
 
   // Prints out all of the messages (like when a test fails).
   void PrintAllMessages() {
-    ::aos::MutexLocker locker(&messages_mutex_);
+    std::unique_lock<aos::stl_mutex> locker(messages_mutex_);
     for (auto it = messages_.begin(); it != messages_.end(); ++it) {
       logging::internal::PrintMessage(stdout, *it);
     }
@@ -69,7 +69,7 @@
 
  private:
   virtual void HandleMessage(const LogMessage &message) override {
-    ::aos::MutexLocker locker(&messages_mutex_);
+    std::unique_lock<aos::stl_mutex> locker(messages_mutex_);
     if (message.level == FATAL || print_as_messages_come_in_) {
       logging::internal::PrintMessage(output_file_, message);
     }
@@ -80,7 +80,7 @@
   ::std::vector<LogMessage> messages_;
   bool print_as_messages_come_in_ = false;
   FILE *output_file_ = stdout;
-  ::aos::Mutex messages_mutex_;
+  aos::stl_mutex messages_mutex_;
 };
 
 class MyTestEventListener : public ::testing::EmptyTestEventListener {
diff --git a/aos/time/BUILD b/aos/time/BUILD
index 619642e..7051564 100644
--- a/aos/time/BUILD
+++ b/aos/time/BUILD
@@ -11,7 +11,6 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos:macros",
-        "//aos/mutex",
         "//aos/type_traits",
         "@com_github_google_glog//:glog",
     ],
diff --git a/frc971/wpilib/BUILD b/frc971/wpilib/BUILD
index 1256d7f..21472f8 100644
--- a/frc971/wpilib/BUILD
+++ b/frc971/wpilib/BUILD
@@ -25,7 +25,6 @@
         ":dma_edge_counting",
         "//aos:init",
         "//aos/logging",
-        "//aos/mutex",
         "//third_party:wpilib",
     ],
 )
diff --git a/frc971/wpilib/encoder_and_potentiometer.cc b/frc971/wpilib/encoder_and_potentiometer.cc
index 8173d20..578fb96 100644
--- a/frc971/wpilib/encoder_and_potentiometer.cc
+++ b/frc971/wpilib/encoder_and_potentiometer.cc
@@ -20,40 +20,5 @@
   return false;
 }
 
-void InterruptEncoderAndPotentiometer::Start() {
-  AOS_CHECK_NE(nullptr, encoder_);
-  AOS_CHECK_NE(nullptr, index_);
-  AOS_CHECK_NE(nullptr, potentiometer_);
-  AOS_CHECK_NE(0, priority_);
-  thread_ = ::std::thread(::std::ref(*this));
-}
-
-void InterruptEncoderAndPotentiometer::operator()() {
-  ::aos::SetCurrentThreadName("IntEncPot_" +
-                              ::std::to_string(potentiometer_->GetChannel()));
-
-  index_->RequestInterrupts();
-  index_->SetUpSourceEdge(true, false);
-
-  ::aos::SetCurrentThreadRealtimePriority(priority_);
-
-  frc::InterruptableSensorBase::WaitResult result =
-      frc::InterruptableSensorBase::kBoth;
-  while (run_) {
-    result = index_->WaitForInterrupt(
-        0.1, result != frc::InterruptableSensorBase::kTimeout);
-    if (result == frc::InterruptableSensorBase::kTimeout) {
-      continue;
-    }
-
-    {
-      ::aos::MutexLocker locker(&mutex_);
-      last_potentiometer_voltage_ = potentiometer_->GetVoltage();
-      last_encoder_value_ = encoder_->GetRaw();
-      ++index_posedge_count_;
-    }
-  }
-}
-
 }  // namespace wpilib
 }  // namespace frc971
diff --git a/frc971/wpilib/encoder_and_potentiometer.h b/frc971/wpilib/encoder_and_potentiometer.h
index eb55664..b86ad54 100644
--- a/frc971/wpilib/encoder_and_potentiometer.h
+++ b/frc971/wpilib/encoder_and_potentiometer.h
@@ -6,7 +6,6 @@
 #include <thread>
 
 #include "aos/macros.h"
-#include "aos/mutex/mutex.h"
 #include "aos/time/time.h"
 
 #include "frc971/wpilib/ahal/AnalogInput.h"
@@ -20,77 +19,6 @@
 namespace frc971 {
 namespace wpilib {
 
-// Latches values from an encoder and potentiometer on positive edges from
-// another input using an interrupt.
-class InterruptEncoderAndPotentiometer {
- public:
-  // priority is the priority the thread will run at.
-  InterruptEncoderAndPotentiometer(int priority) : priority_(priority) {}
-
-  // Starts the thread running so it can receive interrupts.
-  void Start();
-
-  // Tells the thread to stop running and then waits for it to finish.
-  void Stop() {
-    run_ = false;
-    thread_.join();
-  }
-
-  // Loops until Stop() is called, reading interrupts.
-  // Designed to be called by ::std::thread internally.
-  void operator()();
-
-  // Returns the mutex which must be held while calling index_posedge_count(),
-  // last_encoder_value(), and last_potentiometer_voltage().
-  // Holding this mutex will increase the handling latency.
-  ::aos::Mutex *mutex() { return &mutex_; }
-
-  void set_encoder(::std::unique_ptr<frc::Encoder> encoder) {
-    encoder_ = ::std::move(encoder);
-  }
-  frc::Encoder *encoder() const { return encoder_.get(); }
-
-  void set_index(::std::unique_ptr<frc::DigitalSource> index) {
-    index_ = ::std::move(index);
-  }
-  frc::DigitalSource *index() const { return index_.get(); }
-
-  void set_potentiometer(::std::unique_ptr<frc::AnalogInput> potentiometer) {
-    potentiometer_ = ::std::move(potentiometer);
-  }
-  frc::AnalogInput *potentiometer() const { return potentiometer_.get(); }
-
-  // Returns the number of poseges that have happened on the index input.
-  // mutex() must be held while calling this.
-  uint32_t index_posedge_count() const { return index_posedge_count_; }
-  // Returns the value of the encoder at the last index posedge.
-  // mutex() must be held while calling this.
-  int32_t last_encoder_value() const { return last_encoder_value_; }
-  // Returns the voltage of the potentiometer at the last index posedge.
-  // mutex() must be held while calling this.
-  float last_potentiometer_voltage() const {
-    return last_potentiometer_voltage_;
-  }
-
- private:
-  ::std::unique_ptr<frc::Encoder> encoder_;
-  ::std::unique_ptr<frc::DigitalSource> index_;
-  ::std::unique_ptr<frc::AnalogInput> potentiometer_;
-
-  int32_t last_encoder_value_{0};
-  float last_potentiometer_voltage_{0.0f};
-  uint32_t index_posedge_count_{0};
-
-  ::aos::Mutex mutex_;
-
-  const int priority_;
-
-  ::std::atomic<bool> run_{true};
-  ::std::thread thread_;
-
-  DISALLOW_COPY_AND_ASSIGN(InterruptEncoderAndPotentiometer);
-};
-
 // Latches values from an encoder on positive edges from another input using
 // DMA.
 class DMAEncoder : public DMASampleHandlerInterface {
diff --git a/y2014/BUILD b/y2014/BUILD
index 6ff529a..c77a019 100644
--- a/y2014/BUILD
+++ b/y2014/BUILD
@@ -12,8 +12,8 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
-        "//aos/mutex",
         "//aos/network:team_number",
+        "//aos/stl_mutex",
         "//frc971:shifter_hall_effect",
         "//frc971/control_loops:state_feedback_loop",
         "//y2014/control_loops/drivetrain:polydrivetrain_plants",
diff --git a/y2014/constants.cc b/y2014/constants.cc
index a1b8d2a..4c4c5cf 100644
--- a/y2014/constants.cc
+++ b/y2014/constants.cc
@@ -1,8 +1,8 @@
 #include "y2014/constants.h"
 
+#include <inttypes.h>
 #include <math.h>
 #include <stdint.h>
-#include <inttypes.h>
 
 #include <map>
 
@@ -10,13 +10,13 @@
 #include "sanitizer/lsan_interface.h"
 #endif
 
-#include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
-#include "aos/network/team_number.h"
 #include "absl/base/call_once.h"
+#include "aos/logging/logging.h"
+#include "aos/network/team_number.h"
+#include "aos/stl_mutex/stl_mutex.h"
 
-#include "y2014/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
 #include "y2014/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
+#include "y2014/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
@@ -39,11 +39,15 @@
 const double kPracticeLowGearRatio = kCompLowGearRatio;
 const double kPracticeHighGearRatio = kCompHighGearRatio;
 
-const DualHallShifterHallEffect kCompLeftDriveShifter{{2.33, 4.25, 0.2, 0.7}, 2.61, 3.28};
-const DualHallShifterHallEffect kCompRightDriveShifter{{4.31, 4.32, 0.2, 0.7}, 2.94, 3.25};
+const DualHallShifterHallEffect kCompLeftDriveShifter{
+    {2.33, 4.25, 0.2, 0.7}, 2.61, 3.28};
+const DualHallShifterHallEffect kCompRightDriveShifter{
+    {4.31, 4.32, 0.2, 0.7}, 2.94, 3.25};
 
-const DualHallShifterHallEffect kPracticeLeftDriveShifter{{3.05, 4.15, 0.2, 0.7}, 2.80, 3.2};
-const DualHallShifterHallEffect kPracticeRightDriveShifter{{3.75, 3.80, 0.2, 0.7}, 2.90, 2.98};
+const DualHallShifterHallEffect kPracticeLeftDriveShifter{
+    {3.05, 4.15, 0.2, 0.7}, 2.80, 3.2};
+const DualHallShifterHallEffect kPracticeRightDriveShifter{
+    {3.75, 3.80, 0.2, 0.7}, 2.90, 2.98};
 
 const double shooter_zeroing_speed = 0.05;
 const double shooter_unload_speed = 0.08;
@@ -63,30 +67,46 @@
           false,
           ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
           ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
-          5.0, // drivetrain max speed
+          5.0,  // drivetrain max speed
 
           // ShooterLimits
-          {-0.00127, 0.298196, -0.0017, 0.305054, 0.0149098,
+          {-0.00127,
+           0.298196,
+           -0.0017,
+           0.305054,
+           0.0149098,
            {-0.001778, 0.000762, 0, 0},
            {-0.001778, 0.008906, 0, 0},
            {0.006096, 0.026416, 0, 0},
            shooter_zeroing_speed,
-           shooter_unload_speed
+           shooter_unload_speed},
+          {
+              0.5,
+              0.1,
+              0.1,
+              0.0,
+              1.57,
+              0.05,
+              1.5,
+              {0.0,
+               2.05,
+               0.02,
+               2.02,
+               {-0.1, 0.05, -0.1, 0.05},
+               {1.0, 1.1, 1.0, 1.1},
+               {2.0, 2.1, 2.0, 2.1}},
+              {0.0,
+               2.05,
+               0.02,
+               2.02,
+               {-0.1, 0.05, -0.1, 0.05},
+               {1.0, 1.1, 1.0, 1.1},
+               {2.0, 2.1, 2.0, 2.1}},
+              0.01,  // claw_unimportant_epsilon
+              0.9,   // start_fine_tune_pos
+              4.0,
           },
-          {0.5,
-           0.1,
-           0.1,
-           0.0,
-           1.57,
-           0.05,
-           1.5,
-           {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, -0.1, 0.05}, {1.0, 1.1, 1.0, 1.1}, {2.0, 2.1, 2.0, 2.1}},
-           {0.0, 2.05, 0.02, 2.02, {-0.1, 0.05, -0.1, 0.05}, {1.0, 1.1, 1.0, 1.1}, {2.0, 2.1, 2.0, 2.1}},
-           0.01,  // claw_unimportant_epsilon
-           0.9,   // start_fine_tune_pos
-           4.0,
-          },
-          {0.07, 0.15}, // shooter_action
+          {0.07, 0.15},  // shooter_action
       };
       break;
     case kCompTeamNumber:
@@ -99,38 +119,51 @@
           false,
           ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
           ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
-          5.0, // drivetrain max speed
+          5.0,  // drivetrain max speed
 
           // ShooterLimits
-          {-0.001041, 0.296019, -0.001488, 0.302717, 0.0149098,
+          {-0.001041,
+           0.296019,
+           -0.001488,
+           0.302717,
+           0.0149098,
            {-0.002, 0.000446, -0.002, 0.000446},
            {-0.002, 0.009078, -0.002, 0.009078},
            {0.003870, 0.026194, 0.003869, 0.026343},
            shooter_zeroing_speed,
-           shooter_unload_speed
+           shooter_unload_speed},
+          {
+              0.800000,
+              0.400000,
+              0.000000,
+              -1.220821,
+              1.822142,
+              -0.849484,
+              1.42309,
+              // 0.0371
+              {-3.3284,
+               2.0917,
+               -3.1661,
+               1.95,
+               {-3.4, -3.02 + kCompTopClawOffset, -3.4,
+                -2.9876 + kCompTopClawOffset},
+               {-0.1433 + kCompTopClawOffset, 0.0670 + kCompTopClawOffset,
+                -0.1460 + kCompTopClawOffset, 0.0648 + kCompTopClawOffset},
+               {1.9952 + kCompTopClawOffset, 2.2, 1.9898 + kCompTopClawOffset,
+                2.2}},
+              {-2.453460,
+               3.082960,
+               -2.453460,
+               3.082960,
+               {-2.6, -2.185752, -2.6, -2.184843},
+               {-0.322249, -0.053177, -0.332248, -0.059086},
+               {2.892065, 3.2, 2.888429, 3.2}},
+              0.040000,   // claw_unimportant_epsilon
+              -0.400000,  // start_fine_tune_pos
+              4.000000,
           },
-          {0.800000,
-           0.400000,
-           0.000000,
-           -1.220821,
-           1.822142,
-           -0.849484,
-           1.42309,
-           // 0.0371
-           {-3.3284, 2.0917, -3.1661, 1.95,
-             {-3.4, -3.02 + kCompTopClawOffset, -3.4, -2.9876 + kCompTopClawOffset},
-             {-0.1433 + kCompTopClawOffset, 0.0670 + kCompTopClawOffset, -0.1460 + kCompTopClawOffset, 0.0648 + kCompTopClawOffset},
-             {1.9952 + kCompTopClawOffset, 2.2, 1.9898 + kCompTopClawOffset, 2.2}},
-           {-2.453460, 3.082960, -2.453460, 3.082960,
-             {-2.6, -2.185752, -2.6, -2.184843},
-             {-0.322249, -0.053177, -0.332248, -0.059086},
-             {2.892065, 3.2, 2.888429, 3.2}},
-           0.040000,  // claw_unimportant_epsilon
-           -0.400000,   // start_fine_tune_pos
-           4.000000,
-          },
-          //TODO(james): Get realer numbers for shooter_action.
-          {0.07, 0.15}, // shooter_action
+          // TODO(james): Get realer numbers for shooter_action.
+          {0.07, 0.15},  // shooter_action
       };
       break;
     case kPracticeTeamNumber:
@@ -144,37 +177,51 @@
           false,
           ::y2014::control_loops::drivetrain::MakeVelocityDrivetrainLoop,
           ::y2014::control_loops::drivetrain::MakeDrivetrainLoop,
-          5.0, // drivetrain max speed
+          5.0,  // drivetrain max speed
 
           // ShooterLimits
-          {-0.001042, 0.294084, -0.001935, 0.303460, 0.0138401,
+          {-0.001042,
+           0.294084,
+           -0.001935,
+           0.303460,
+           0.0138401,
            {-0.002, 0.000446, -0.002, 0.000446},
            {-0.002 + 0.001, 0.009078 + 0.001, -0.002 + 0.001, 0.009078 + 0.001},
-           {0.003869 + 0.001, 0.026194 + 0.001, 0.003869 + 0.001, 0.026194 + 0.001},
+           {0.003869 + 0.001, 0.026194 + 0.001, 0.003869 + 0.001,
+            0.026194 + 0.001},
            shooter_zeroing_speed,
-           shooter_unload_speed
+           shooter_unload_speed},
+          {
+              0.400000 * 2.0,
+              0.200000 * 2.0,
+              0.000000 * 2.0,
+              -0.762218 * 2.0,
+              1.767146,
+              -0.849484,
+              1.42308,
+              {-3.364758,
+               2.086668,
+               -3.166136,
+               1.95,
+               {-1.7 * 2.0, -1.544662 * 2.0 + 0.139081, -1.7 * 2.0,
+                -1.547616 * 2.0 + 0.139081 + 0.013636},
+               {-0.115446 * 2.0, 0.030452 * 2.0, -0.120900 * 2.0,
+                0.023862 * 2.0},
+               {0.977884 * 2.0, 1.4 * 2.0, 0.963113 * 2.0, 1.4 * 2.0}},
+              {-2.451642,
+               3.107504,
+               -2.273474,
+               2.750,
+               {-1.5 * 2.0, -1.027199 * 2.0, -1.5 * 2.0, -1.037880 * 2.0},
+               {-0.116355 * 2.0, 0.017726 * 2.0, -0.125673 * 2.0,
+                0.008636 * 2.0},
+               {2.894792 + 0.122719, 3.2, 2.887974 + 0.122719 - 0.029088, 3.2}},
+              0.040000,   // claw_unimportant_epsilon
+              -0.400000,  // start_fine_tune_pos
+              4.000000,
           },
-          {0.400000 * 2.0,
-          0.200000 * 2.0,
-          0.000000 * 2.0,
-          -0.762218 * 2.0,
-          1.767146,
-          -0.849484,
-          1.42308,
-          {-3.364758, 2.086668, -3.166136, 1.95,
-            {-1.7 * 2.0, -1.544662 * 2.0 + 0.139081, -1.7 * 2.0, -1.547616 * 2.0 + 0.139081+ 0.013636},
-            {-0.115446 * 2.0, 0.030452 * 2.0, -0.120900 * 2.0, 0.023862 * 2.0},
-            {0.977884 * 2.0, 1.4 * 2.0, 0.963113 * 2.0, 1.4 * 2.0}},
-          {-2.451642, 3.107504, -2.273474, 2.750,
-            {-1.5 * 2.0, -1.027199 * 2.0, -1.5 * 2.0, -1.037880 * 2.0},
-            {-0.116355 * 2.0, 0.017726 * 2.0, -0.125673 * 2.0, 0.008636 * 2.0},
-            {2.894792 + 0.122719, 3.2, 2.887974 + 0.122719 - 0.029088, 3.2}},
-          0.040000,  // claw_unimportant_epsilon
-          -0.400000,   // start_fine_tune_pos
-          4.000000,
-          },
-          //TODO(james): Get realer numbers for shooter_action.
-          {0.07, 0.15}, // shooter_action
+          // TODO(james): Get realer numbers for shooter_action.
+          {0.07, 0.15},  // shooter_action
       };
       break;
     default:
@@ -199,8 +246,8 @@
 }
 
 const Values &GetValuesForTeam(uint16_t team_number) {
-  static ::aos::Mutex mutex;
-  ::aos::MutexLocker locker(&mutex);
+  static aos::stl_mutex mutex;
+  std::unique_lock<aos::stl_mutex> locker(mutex);
 
   // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
   // race conditions.
diff --git a/y2016/BUILD b/y2016/BUILD
index 190e0e0..6944d4f 100644
--- a/y2016/BUILD
+++ b/y2016/BUILD
@@ -12,8 +12,8 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
-        "//aos/mutex",
         "//aos/network:team_number",
+        "//aos/stl_mutex",
         "//frc971:constants",
         "//frc971:shifter_hall_effect",
         "//frc971/control_loops:state_feedback_loop",
diff --git a/y2016/constants.cc b/y2016/constants.cc
index 2b75345..1f4ae9e 100644
--- a/y2016/constants.cc
+++ b/y2016/constants.cc
@@ -1,8 +1,8 @@
 #include "y2016/constants.h"
 
+#include <inttypes.h>
 #include <math.h>
 #include <stdint.h>
-#include <inttypes.h>
 
 #include <map>
 
@@ -10,13 +10,13 @@
 #include "sanitizer/lsan_interface.h"
 #endif
 
-#include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
-#include "aos/network/team_number.h"
 #include "absl/base/call_once.h"
+#include "aos/logging/logging.h"
+#include "aos/network/team_number.h"
+#include "aos/stl_mutex/stl_mutex.h"
 
-#include "y2016/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
 #include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
+#include "y2016/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
@@ -52,23 +52,23 @@
 
           // Intake
           {
-           0.0,
-           {Values::kZeroingSampleSize, Values::kIntakeEncoderIndexDifference,
-            0.0, 0.3},
+              0.0,
+              {Values::kZeroingSampleSize,
+               Values::kIntakeEncoderIndexDifference, 0.0, 0.3},
           },
 
           // Shoulder
           {
-           0.0,
-           {Values::kZeroingSampleSize, Values::kShoulderEncoderIndexDifference,
-            0.0, 0.3},
+              0.0,
+              {Values::kZeroingSampleSize,
+               Values::kShoulderEncoderIndexDifference, 0.0, 0.3},
           },
 
           // Wrist
           {
-           0.0,
-           {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
-            0.0, 0.3},
+              0.0,
+              {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
+               0.0, 0.3},
           },
 
           0.0,
@@ -81,27 +81,32 @@
           5.0,  // drivetrain max speed
 
           // Intake
-          {// Value to add to the pot reading for the intake.
-           -4.550531 + 150.40906362 * M_PI / 180.0 + 0.5098 - 0.0178 - 0.0725,
-           {Values::kZeroingSampleSize, Values::kIntakeEncoderIndexDifference,
-            // Location of an index pulse.
-            0.018008, 2.5},
+          {
+              // Value to add to the pot reading for the intake.
+              -4.550531 + 150.40906362 * M_PI / 180.0 + 0.5098 - 0.0178 -
+                  0.0725,
+              {Values::kZeroingSampleSize,
+               Values::kIntakeEncoderIndexDifference,
+               // Location of an index pulse.
+               0.018008, 2.5},
           },
 
           // Shoulder
-          {// Value to add to the pot reading for the shoulder.
-           -2.86275657117,
-           {Values::kZeroingSampleSize, Values::kShoulderEncoderIndexDifference,
-            0.097312, 2.5},
+          {
+              // Value to add to the pot reading for the shoulder.
+              -2.86275657117,
+              {Values::kZeroingSampleSize,
+               Values::kShoulderEncoderIndexDifference, 0.097312, 2.5},
           },
 
           // Wrist
-          {// Value to add to the pot reading for the wrist.
-           3.2390714288298668 + -0.06138835 * M_PI / 180.0 + 0.0078 - 0.0548 -
-               0.0167 + 0.002 - 0.0026 - 0.1040 - 0.0035 - 0.0012 + 0.0166 -
-               0.017 + 0.148 + 0.004 + 0.024701 - 0.0741,
-           {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
-            0.000820, 2.5},
+          {
+              // Value to add to the pot reading for the wrist.
+              3.2390714288298668 + -0.06138835 * M_PI / 180.0 + 0.0078 -
+                  0.0548 - 0.0167 + 0.002 - 0.0026 - 0.1040 - 0.0035 - 0.0012 +
+                  0.0166 - 0.017 + 0.148 + 0.004 + 0.024701 - 0.0741,
+              {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
+               0.000820, 2.5},
           },
 
           0.0,
@@ -113,28 +118,29 @@
           5.0,  // drivetrain max speed
 
           // Intake
-          {// Hard stop is 160.0185751389329 degrees.
-           -4.2193 + (160.0185751389329 * M_PI / 180.0 + 0.02 - 0.0235) +
-               0.0549 - 0.104 + 0.019 - 0.938 + 0.660 - 0.002 - 0.2081,
-           {Values::kZeroingSampleSize, Values::kIntakeEncoderIndexDifference,
-            0.332370, 1.3},
+          {
+              // Hard stop is 160.0185751389329 degrees.
+              -4.2193 + (160.0185751389329 * M_PI / 180.0 + 0.02 - 0.0235) +
+                  0.0549 - 0.104 + 0.019 - 0.938 + 0.660 - 0.002 - 0.2081,
+              {Values::kZeroingSampleSize,
+               Values::kIntakeEncoderIndexDifference, 0.332370, 1.3},
           },
 
           // Shoulder (Now calibrated at 0)
           {
-           -1.0016 - 0.0841 + 0.06138835 * M_PI / 180.0 + 1.07838 - 1.0441 +
-               0.0034 + 0.0065 - 0.0505,
-           {Values::kZeroingSampleSize, Values::kShoulderEncoderIndexDifference,
-            0.027180, 1.3},
+              -1.0016 - 0.0841 + 0.06138835 * M_PI / 180.0 + 1.07838 - 1.0441 +
+                  0.0034 + 0.0065 - 0.0505,
+              {Values::kZeroingSampleSize,
+               Values::kShoulderEncoderIndexDifference, 0.027180, 1.3},
           },
 
           // Wrist
           {
-           3.326328571170133 - 0.06138835 * M_PI / 180.0 - 0.177 + 0.0323 -
-               0.023 + 0.0488 + 0.0120 - 0.0005 - 0.0784 - 0.0010 - 0.080 +
-               0.1245,
-           {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
-            -0.263227, 1.3},
+              3.326328571170133 - 0.06138835 * M_PI / 180.0 - 0.177 + 0.0323 -
+                  0.023 + 0.0488 + 0.0120 - 0.0005 - 0.0784 - 0.0010 - 0.080 +
+                  0.1245,
+              {Values::kZeroingSampleSize, Values::kWristEncoderIndexDifference,
+               -0.263227, 1.3},
           },
 
           0.011,
@@ -163,8 +169,8 @@
 }
 
 const Values &GetValuesForTeam(uint16_t team_number) {
-  static ::aos::Mutex mutex;
-  ::aos::MutexLocker locker(&mutex);
+  static aos::stl_mutex mutex;
+  std::unique_lock<aos::stl_mutex> locker(mutex);
 
   // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
   // race conditions.
diff --git a/y2016/dashboard/dashboard.cc b/y2016/dashboard/dashboard.cc
index 74df0a5..ae4f7ed 100644
--- a/y2016/dashboard/dashboard.cc
+++ b/y2016/dashboard/dashboard.cc
@@ -14,9 +14,9 @@
 #include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
 #include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
 #include "aos/realtime.h"
 #include "aos/seasocks/seasocks_logger.h"
+#include "aos/stl_mutex/stl_mutex.h"
 #include "aos/time/time.h"
 #include "aos/util/phased_loop.h"
 #include "frc971/autonomous/auto_mode_generated.h"
@@ -52,8 +52,7 @@
 DataCollector::DataCollector(::aos::EventLoop *event_loop)
     : event_loop_(event_loop),
       vision_status_fetcher_(
-          event_loop->MakeFetcher<::y2016::vision::VisionStatus>(
-              "/vision")),
+          event_loop->MakeFetcher<::y2016::vision::VisionStatus>("/vision")),
       ball_detector_fetcher_(
           event_loop->MakeFetcher<::y2016::sensors::BallDetector>(
               "/superstructure")),
@@ -70,7 +69,7 @@
       overflow_id_(1) {}
 
 void DataCollector::RunIteration() {
-  ::aos::MutexLocker locker(&mutex_);
+  std::unique_lock<aos::stl_mutex> locker(mutex_);
   measure_index_ = 0;
 
 // Add recorded data here. /////
@@ -153,7 +152,7 @@
 
 void DataCollector::AddPoint(const ::std::string &name, double value) {
   // Mutex should be locked when this method is called to synchronize packets.
-  AOS_CHECK(mutex_.OwnedBySelf());
+  AOS_CHECK(mutex_islocked(mutex_.native_handle()));
 
   size_t index = GetIndex(sample_id_);
 
@@ -175,7 +174,7 @@
 }
 
 ::std::string DataCollector::Fetch(int32_t from_sample) {
-  ::aos::MutexLocker locker(&mutex_);
+  std::unique_lock<aos::stl_mutex> locker(mutex_);
 
   ::std::stringstream message;
   message.precision(10);
diff --git a/y2016/dashboard/dashboard.h b/y2016/dashboard/dashboard.h
index cc51a8b..b4d5034 100644
--- a/y2016/dashboard/dashboard.h
+++ b/y2016/dashboard/dashboard.h
@@ -1,12 +1,12 @@
 #ifndef Y2016_DASHBOARD_DASHBOARD_H_
 #define Y2016_DASHBOARD_DASHBOARD_H_
 
+#include <atomic>
 #include <iostream>
 #include <memory>
 #include <sstream>
 #include <string>
 #include <thread>
-#include <atomic>
 #include <vector>
 
 #include "seasocks/PageHandler.h"
@@ -15,7 +15,7 @@
 #include "seasocks/WebSocket.h"
 
 #include "aos/events/event_loop.h"
-#include "aos/mutex/mutex.h"
+#include "aos/stl_mutex/stl_mutex.h"
 #include "aos/time/time.h"
 #include "frc971/autonomous/auto_mode_generated.h"
 #include "y2016/control_loops/superstructure/superstructure_status_generated.h"
@@ -79,23 +79,23 @@
 
   ::std::string cur_raw_data_;
   int32_t sample_id_;          // Last sample id used.
-  size_t measure_index_;      // Last measure index used.
+  size_t measure_index_;       // Last measure index used.
   const int32_t overflow_id_;  // Vector wrapping size.
 
   ::std::atomic<bool> run_{true};
-  ::aos::Mutex mutex_;
+  aos::stl_mutex mutex_;
 };
 
 class SocketHandler : public seasocks::WebSocket::Handler {
  public:
   SocketHandler(::aos::EventLoop *event_loop);
-  void onConnect(seasocks::WebSocket* connection) override;
-  void onData(seasocks::WebSocket* connection, const char* data) override;
-  void onDisconnect(seasocks::WebSocket* connection) override;
+  void onConnect(seasocks::WebSocket *connection) override;
+  void onData(seasocks::WebSocket *connection, const char *data) override;
+  void onDisconnect(seasocks::WebSocket *connection) override;
   void Quit();
 
  private:
-  ::std::set<seasocks::WebSocket*> connections_;
+  ::std::set<seasocks::WebSocket *> connections_;
   DataCollector data_collector_;
   ::std::thread data_collector_thread_;
 };
@@ -103,7 +103,7 @@
 class SeasocksLogger : public seasocks::PrintfLogger {
  public:
   SeasocksLogger(Level min_level_to_log);
-  void log(Level level, const char* message) override;
+  void log(Level level, const char *message) override;
 };
 
 }  // namespace dashboard
diff --git a/y2016/vision/BUILD b/y2016/vision/BUILD
index c4d472b..072b6ca 100644
--- a/y2016/vision/BUILD
+++ b/y2016/vision/BUILD
@@ -135,7 +135,6 @@
         "//aos:init",
         "//aos/events:shm_event_loop",
         "//aos/logging",
-        "//aos/mutex",
         "//aos/time",
         "//aos/vision/events:udp",
         "//frc971/control_loops:control_loops_fbs",
diff --git a/y2016/vision/target_receiver.cc b/y2016/vision/target_receiver.cc
index 93ec131..0dd5cb9 100644
--- a/y2016/vision/target_receiver.cc
+++ b/y2016/vision/target_receiver.cc
@@ -14,7 +14,6 @@
 #include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
 #include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
 #include "aos/time/time.h"
 #include "aos/vision/events/udp.h"
 #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
diff --git a/y2017/BUILD b/y2017/BUILD
index ca3e221..3c1fe21 100644
--- a/y2017/BUILD
+++ b/y2017/BUILD
@@ -12,8 +12,8 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
-        "//aos/mutex",
         "//aos/network:team_number",
+        "//aos/stl_mutex",
         "//frc971:constants",
         "//frc971/shooter_interpolation:interpolation",
         "//y2017/control_loops/drivetrain:polydrivetrain_plants",
diff --git a/y2017/constants.cc b/y2017/constants.cc
index c11dbcc..ab062e2 100644
--- a/y2017/constants.cc
+++ b/y2017/constants.cc
@@ -10,10 +10,10 @@
 #include "sanitizer/lsan_interface.h"
 #endif
 
-#include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
-#include "aos/network/team_number.h"
 #include "absl/base/call_once.h"
+#include "aos/logging/logging.h"
+#include "aos/network/team_number.h"
+#include "aos/stl_mutex/stl_mutex.h"
 
 #include "y2017/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
 #include "y2017/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
@@ -68,7 +68,8 @@
   r->drivetrain_max_speed = 5;
 
   intake->zeroing.average_filter_size = Values::kZeroingSampleSize;
-  intake->zeroing.one_revolution_distance = Values::kIntakeEncoderIndexDifference;
+  intake->zeroing.one_revolution_distance =
+      Values::kIntakeEncoderIndexDifference;
   intake->zeroing.zeroing_threshold = 0.0005;
   intake->zeroing.moving_buffer_size = 20;
   intake->zeroing.allowable_encoder_error = 1.9;
@@ -152,7 +153,7 @@
   return r;
 }
 
-void DoGetValues(const Values** result) {
+void DoGetValues(const Values **result) {
   uint16_t team = ::aos::network::GetTeamNumber();
   AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
   *result = DoGetValuesForTeam(team);
@@ -162,14 +163,14 @@
 
 const Values &GetValues() {
   static absl::once_flag once;
-  static const Values* result;
+  static const Values *result;
   absl::call_once(once, DoGetValues, &result);
   return *result;
 }
 
 const Values &GetValuesForTeam(uint16_t team_number) {
-  static ::aos::Mutex mutex;
-  ::aos::MutexLocker locker(&mutex);
+  static aos::stl_mutex mutex;
+  std::unique_lock<aos::stl_mutex> locker(mutex);
 
   // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
   // race conditions.
@@ -184,11 +185,14 @@
   return *values[team_number];
 }
 
-Values::ShotParams Values::ShotParams::BlendY(double coefficient, Values::ShotParams a1, Values::ShotParams a2) {
+Values::ShotParams Values::ShotParams::BlendY(double coefficient,
+                                              Values::ShotParams a1,
+                                              Values::ShotParams a2) {
   using ::frc971::shooter_interpolation::Blend;
-  return Values::ShotParams{Blend(coefficient, a1.angle, a2.angle),
-                    Blend(coefficient, a1.power, a2.power),
-                    Blend(coefficient, a1.indexer_velocity, a2.indexer_velocity)};
+  return Values::ShotParams{
+      Blend(coefficient, a1.angle, a2.angle),
+      Blend(coefficient, a1.power, a2.power),
+      Blend(coefficient, a1.indexer_velocity, a2.indexer_velocity)};
 }
 
 }  // namespace constants
diff --git a/y2017/vision/BUILD b/y2017/vision/BUILD
index 1997870..a71fc8a 100644
--- a/y2017/vision/BUILD
+++ b/y2017/vision/BUILD
@@ -64,7 +64,6 @@
         "//aos:init",
         "//aos/events:shm_event_loop",
         "//aos/logging",
-        "//aos/mutex",
         "//aos/time",
         "//aos/vision/events:udp",
     ],
diff --git a/y2018/BUILD b/y2018/BUILD
index 94fd844..cf3951e 100644
--- a/y2018/BUILD
+++ b/y2018/BUILD
@@ -52,8 +52,8 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
-        "//aos/mutex",
         "//aos/network:team_number",
+        "//aos/stl_mutex",
         "//frc971:constants",
         "//frc971/shooter_interpolation:interpolation",
         "//y2018/control_loops/drivetrain:polydrivetrain_plants",
diff --git a/y2018/constants.cc b/y2018/constants.cc
index ea21a5b..156bc5b 100644
--- a/y2018/constants.cc
+++ b/y2018/constants.cc
@@ -11,8 +11,8 @@
 #endif
 
 #include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
 #include "aos/network/team_number.h"
+#include "aos/stl_mutex/stl_mutex.h"
 
 #include "y2018/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
 #include "y2018/control_loops/drivetrain/polydrivetrain_dog_motor_plant.h"
@@ -102,7 +102,8 @@
 
       arm_distal->zeroing.measured_absolute_position =
           -0.870445 + 5.209807817203074 + 0.118 - 0.004 + 0.407 - 0.53;
-      arm_distal->potentiometer_offset = 5.209807817203074 + 1.250476 + 0.110 + 0.52;
+      arm_distal->potentiometer_offset =
+          5.209807817203074 + 1.250476 + 0.110 + 0.52;
       break;
 
     case kPracticeTeamNumber:
@@ -117,13 +118,15 @@
       right_intake->potentiometer_offset = 9.59 + 1.530320 - 3.620648;
       right_intake->spring_offset = 0.255 + 0.008 - 0.09;
 
-      arm_proximal->zeroing.measured_absolute_position = -0.253183 + 1.0652774488034022 + 0.009566448803402405;
+      arm_proximal->zeroing.measured_absolute_position =
+          -0.253183 + 1.0652774488034022 + 0.009566448803402405;
       arm_proximal->potentiometer_offset = -1.242 - 0.03 - 0.1 - 1.0652;
 
       arm_distal->zeroing.measured_absolute_position =
-          1.102987 - kDistalZeroingPosition + 0.12 + 0.0095 + 0.22300918279692628;
-      arm_distal->potentiometer_offset =
-          2.772210 + M_PI + 0.434 - 0.12 + 1.25 - 0.226 + 0.862067 - 0.121925182796926;
+          1.102987 - kDistalZeroingPosition + 0.12 + 0.0095 +
+          0.22300918279692628;
+      arm_distal->potentiometer_offset = 2.772210 + M_PI + 0.434 - 0.12 + 1.25 -
+                                         0.226 + 0.862067 - 0.121925182796926;
       break;
 
     default:
@@ -147,8 +150,8 @@
 }
 
 const Values &GetValuesForTeam(uint16_t team_number) {
-  static ::aos::Mutex mutex;
-  ::aos::MutexLocker locker(&mutex);
+  static aos::stl_mutex mutex;
+  std::unique_lock<aos::stl_mutex> locker(mutex);
 
   static ::std::map<uint16_t, const Values *> values;
 
diff --git a/y2019/BUILD b/y2019/BUILD
index 1d8b996..ddc0a19 100644
--- a/y2019/BUILD
+++ b/y2019/BUILD
@@ -31,8 +31,8 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
-        "//aos/mutex",
         "//aos/network:team_number",
+        "//aos/stl_mutex",
         "//frc971:constants",
         "//frc971/control_loops:pose",
         "//frc971/control_loops:static_zeroing_single_dof_profiled_subsystem",
diff --git a/y2019/constants.cc b/y2019/constants.cc
index d5b0c09..b14ac3e 100644
--- a/y2019/constants.cc
+++ b/y2019/constants.cc
@@ -8,10 +8,10 @@
 #include "sanitizer/lsan_interface.h"
 #endif
 
-#include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
-#include "aos/network/team_number.h"
 #include "absl/base/call_once.h"
+#include "aos/logging/logging.h"
+#include "aos/network/team_number.h"
+#include "aos/stl_mutex/stl_mutex.h"
 #include "y2019/control_loops/superstructure/elevator/integral_elevator_plant.h"
 #include "y2019/control_loops/superstructure/intake/integral_intake_plant.h"
 #include "y2019/control_loops/superstructure/stilts/integral_stilts_plant.h"
@@ -230,7 +230,7 @@
   return r;
 }
 
-void DoGetValues(const Values** result) {
+void DoGetValues(const Values **result) {
   uint16_t team = ::aos::network::GetTeamNumber();
   AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
   *result = DoGetValuesForTeam(team);
@@ -240,14 +240,14 @@
 
 const Values &GetValues() {
   static absl::once_flag once;
-  static const Values* result;
+  static const Values *result;
   absl::call_once(once, DoGetValues, &result);
   return *result;
 }
 
 const Values &GetValuesForTeam(uint16_t team_number) {
-  static ::aos::Mutex mutex;
-  ::aos::MutexLocker locker(&mutex);
+  static aos::stl_mutex mutex;
+  std::unique_lock<aos::stl_mutex> locker(mutex);
 
   // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
   // race conditions.
diff --git a/y2020/BUILD b/y2020/BUILD
index 38832b8..208b04a 100644
--- a/y2020/BUILD
+++ b/y2020/BUILD
@@ -55,8 +55,8 @@
     visibility = ["//visibility:public"],
     deps = [
         "//aos/logging",
-        "//aos/mutex",
         "//aos/network:team_number",
+        "//aos/stl_mutex",
         "//frc971:constants",
         "//frc971/control_loops:static_zeroing_single_dof_profiled_subsystem",
         "//y2020/control_loops/drivetrain:polydrivetrain_plants",
diff --git a/y2020/constants.cc b/y2020/constants.cc
index 131b0de..d39e1cd 100644
--- a/y2020/constants.cc
+++ b/y2020/constants.cc
@@ -10,8 +10,8 @@
 
 #include "absl/base/call_once.h"
 #include "aos/logging/logging.h"
-#include "aos/mutex/mutex.h"
 #include "aos/network/team_number.h"
+#include "aos/stl_mutex/stl_mutex.h"
 #include "y2020/control_loops/superstructure/control_panel/integral_control_panel_plant.h"
 #include "y2020/control_loops/superstructure/hood/integral_hood_plant.h"
 #include "y2020/control_loops/superstructure/intake/integral_intake_plant.h"
@@ -156,8 +156,8 @@
 }
 
 const Values &GetValuesForTeam(uint16_t team_number) {
-  static ::aos::Mutex mutex;
-  ::aos::MutexLocker locker(&mutex);
+  static aos::stl_mutex mutex;
+  std::unique_lock<aos::stl_mutex> locker(mutex);
 
   // IMPORTANT: This declaration has to stay after the mutex is locked to
   // avoid race conditions.