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/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"