Use wpi::mutex instead of std::mutex. (#730)

This uses a priority-aware mutex on Linux platforms.

Fixes #729.
This commit is contained in:
Peter Johnson
2017-11-13 09:51:48 -08:00
committed by GitHub
parent 35d68d2a34
commit 4d559f3856
86 changed files with 491 additions and 839 deletions

View File

@@ -11,13 +11,13 @@
#include <atomic>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include <llvm/DenseMap.h>
#include <llvm/StringMap.h>
#include <llvm/StringRef.h>
#include <support/mutex.h>
#include "ErrorBase.h"
#include "cscore.h"
@@ -300,7 +300,7 @@ class CameraServer : public ErrorBase {
static constexpr char const* kPublishName = "/CameraPublisher";
std::mutex m_mutex;
wpi::mutex m_mutex;
std::atomic<int> m_defaultUsbDevice;
std::string m_primarySourceName;
llvm::StringMap<cs::VideoSource> m_sources;

View File

@@ -10,11 +10,12 @@
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <vector>
#include <support/mutex.h>
#include "Commands/Command.h"
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
@@ -53,11 +54,11 @@ class Scheduler : public ErrorBase, public NamedSendable {
void ProcessCommandAddition(Command* command);
Command::SubsystemSet m_subsystems;
std::mutex m_buttonsLock;
wpi::mutex m_buttonsLock;
typedef std::vector<ButtonScheduler*> ButtonVector;
ButtonVector m_buttons;
typedef std::vector<Command*> CommandVector;
std::mutex m_additionsLock;
wpi::mutex m_additionsLock;
CommandVector m_additions;
typedef std::set<Command*> CommandSet;
CommandSet m_commands;

View File

@@ -10,7 +10,8 @@
#include <stdint.h>
#include <array>
#include <mutex>
#include <support/mutex.h>
#include "DigitalSource.h"
@@ -51,7 +52,7 @@ class DigitalGlitchFilter : public SensorBase {
void DoAdd(DigitalSource* input, int requested_index);
int m_channelIndex = -1;
static std::mutex m_mutex;
static wpi::mutex m_mutex;
static std::array<bool, 3> m_filterAllocated;
};

View File

@@ -10,12 +10,12 @@
#include <array>
#include <atomic>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <HAL/DriverStation.h>
#include <llvm/StringRef.h>
#include <support/mutex.h>
#include "RobotState.h"
#include "SensorBase.h"
@@ -135,7 +135,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
std::thread m_dsThread;
std::atomic<bool> m_isRunning{false};
mutable std::mutex m_cacheDataMutex;
mutable wpi::mutex m_cacheDataMutex;
// Robot state status variables
bool m_userInDisabled = false;
@@ -146,7 +146,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
// Control word variables
mutable HAL_ControlWord m_controlWordCache;
mutable std::chrono::steady_clock::time_point m_lastControlWordUpdate;
mutable std::mutex m_controlWordMutex;
mutable wpi::mutex m_controlWordMutex;
double m_nextMessageTime = 0;
};

View File

@@ -7,9 +7,8 @@
#pragma once
#include <mutex>
#include <llvm/StringRef.h>
#include <support/mutex.h>
#include "Base.h"
#include "Error.h"
@@ -115,7 +114,7 @@ class ErrorBase {
protected:
mutable Error m_error;
// TODO: Replace globalError with a global list of all errors.
static std::mutex _globalErrorMutex;
static wpi::mutex _globalErrorMutex;
static Error _globalError;
};

View File

@@ -7,9 +7,10 @@
#pragma once
#include <mutex>
#include <set>
#include <support/mutex.h>
#include "ErrorBase.h"
namespace frc {
@@ -37,13 +38,13 @@ class MotorSafetyHelper : public ErrorBase {
// the FPGA clock value when this motor has expired
double m_stopTime;
// protect accesses to the state for this object
mutable std::mutex m_syncMutex;
mutable wpi::mutex m_syncMutex;
// the object that is using the helper
MotorSafety* m_safeObject;
// List of all existing MotorSafetyHelper objects.
static std::set<MotorSafetyHelper*> m_helperList;
// protect accesses to the list of helpers
static std::mutex m_listMutex;
static wpi::mutex m_listMutex;
};
} // namespace frc

View File

@@ -11,10 +11,10 @@
#include <atomic>
#include <functional>
#include <mutex>
#include <utility>
#include <HAL/Notifier.h>
#include <support/mutex.h>
#include "ErrorBase.h"
@@ -47,9 +47,9 @@ class Notifier : public ErrorBase {
static void Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle);
// used to constrain execution between destructors and callback
static std::mutex m_destructorMutex;
static wpi::mutex m_destructorMutex;
// held while updating process information
std::mutex m_processMutex;
wpi::mutex m_processMutex;
// HAL handle, atomic for proper destruction
std::atomic<HAL_NotifierHandle> m_notifier{0};
// address of the handler

View File

@@ -9,10 +9,11 @@
#include <atomic>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <support/mutex.h>
#include "Base.h"
#include "Controller.h"
#include "LiveWindow/LiveWindow.h"
@@ -147,7 +148,7 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
std::queue<double> m_buf;
double m_bufTotal = 0;
mutable std::mutex m_mutex;
mutable wpi::mutex m_mutex;
std::unique_ptr<Notifier> m_controlLoop;
Timer m_setpointTimer;

View File

@@ -10,10 +10,11 @@
#include <stdint.h>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include <support/mutex.h>
#include "ErrorBase.h"
namespace frc {
@@ -43,9 +44,9 @@ class Resource : public ErrorBase {
private:
std::vector<bool> m_isAllocated;
std::mutex m_allocateMutex;
wpi::mutex m_allocateMutex;
static std::mutex m_createMutex;
static wpi::mutex m_createMutex;
};
} // namespace frc

View File

@@ -7,7 +7,7 @@
#pragma once
#include <mutex>
#include <support/mutex.h>
#include "Base.h"
@@ -52,7 +52,7 @@ class Timer {
double m_startTime = 0.0;
double m_accumulatedTime = 0.0;
bool m_running = false;
mutable std::mutex m_mutex;
mutable wpi::mutex m_mutex;
};
} // namespace frc