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

@@ -65,7 +65,7 @@ static std::string MakeStreamValue(llvm::StringRef address, int port) {
std::shared_ptr<nt::NetworkTable> CameraServer::GetSourceTable(
CS_Source source) {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_tables.lookup(source);
}
@@ -127,7 +127,7 @@ std::vector<std::string> CameraServer::GetSourceStreamValues(CS_Source source) {
}
void CameraServer::UpdateStreamValues() {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
// Over all the sinks...
for (const auto& i : m_sinks) {
CS_Status status = 0;
@@ -338,7 +338,7 @@ CameraServer::CameraServer()
// Create subtable for the camera
auto table = m_publishTable->GetSubTable(event.name);
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_tables.insert(std::make_pair(event.sourceHandle, table));
}
llvm::SmallString<64> buf;
@@ -591,7 +591,7 @@ void CameraServer::StartAutomaticCapture(const cs::VideoSource& camera) {
cs::CvSink CameraServer::GetVideo() {
cs::VideoSource source;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_primarySourceName.empty()) {
wpi_setWPIErrorWithContext(CameraServerError, "no camera available");
return cs::CvSink{};
@@ -611,7 +611,7 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
name += camera.GetName();
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
auto it = m_sinks.find(name);
if (it != m_sinks.end()) {
auto kind = it->second.GetKind();
@@ -635,7 +635,7 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
cs::CvSink CameraServer::GetVideo(llvm::StringRef name) {
cs::VideoSource source;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
auto it = m_sources.find(name);
if (it == m_sources.end()) {
llvm::SmallString<64> buf;
@@ -659,7 +659,7 @@ cs::CvSource CameraServer::PutVideo(llvm::StringRef name, int width,
cs::MjpegServer CameraServer::AddServer(llvm::StringRef name) {
int port;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
port = m_nextPort++;
}
return AddServer(name, port);
@@ -672,19 +672,19 @@ cs::MjpegServer CameraServer::AddServer(llvm::StringRef name, int port) {
}
void CameraServer::AddServer(const cs::VideoSink& server) {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_sinks.emplace_second(server.GetName(), server);
}
void CameraServer::RemoveServer(llvm::StringRef name) {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_sinks.erase(name);
}
cs::VideoSink CameraServer::GetServer() {
llvm::SmallString<64> name;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_primarySourceName.empty()) {
wpi_setWPIErrorWithContext(CameraServerError, "no camera available");
return cs::VideoSink{};
@@ -696,7 +696,7 @@ cs::VideoSink CameraServer::GetServer() {
}
cs::VideoSink CameraServer::GetServer(llvm::StringRef name) {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
auto it = m_sinks.find(name);
if (it == m_sinks.end()) {
llvm::SmallString<64> buf;
@@ -710,18 +710,18 @@ cs::VideoSink CameraServer::GetServer(llvm::StringRef name) {
void CameraServer::AddCamera(const cs::VideoSource& camera) {
std::string name = camera.GetName();
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_primarySourceName.empty()) m_primarySourceName = name;
m_sources.emplace_second(name, camera);
}
void CameraServer::RemoveCamera(llvm::StringRef name) {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_sources.erase(name);
}
void CameraServer::SetSize(int size) {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_primarySourceName.empty()) return;
auto it = m_sources.find(m_primarySourceName);
if (it == m_sources.end()) return;

View File

@@ -40,7 +40,7 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
* @param command The command to be scheduled
*/
void Scheduler::AddCommand(Command* command) {
std::lock_guard<std::mutex> sync(m_additionsLock);
std::lock_guard<wpi::mutex> sync(m_additionsLock);
if (std::find(m_additions.begin(), m_additions.end(), command) !=
m_additions.end())
return;
@@ -48,7 +48,7 @@ void Scheduler::AddCommand(Command* command) {
}
void Scheduler::AddButton(ButtonScheduler* button) {
std::lock_guard<std::mutex> sync(m_buttonsLock);
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
m_buttons.push_back(button);
}
@@ -114,7 +114,7 @@ void Scheduler::Run() {
{
if (!m_enabled) return;
std::lock_guard<std::mutex> sync(m_buttonsLock);
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
for (auto rButtonIter = m_buttons.rbegin(); rButtonIter != m_buttons.rend();
rButtonIter++) {
(*rButtonIter)->Execute();
@@ -144,7 +144,7 @@ void Scheduler::Run() {
// Add the new things
{
std::lock_guard<std::mutex> sync(m_additionsLock);
std::lock_guard<wpi::mutex> sync(m_additionsLock);
for (auto additionsIter = m_additions.begin();
additionsIter != m_additions.end(); additionsIter++) {
ProcessCommandAddition(*additionsIter);

View File

@@ -23,10 +23,10 @@ using namespace frc;
std::array<bool, 3> DigitalGlitchFilter::m_filterAllocated = {
{false, false, false}};
std::mutex DigitalGlitchFilter::m_mutex;
wpi::mutex DigitalGlitchFilter::m_mutex;
DigitalGlitchFilter::DigitalGlitchFilter() {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
auto index =
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
wpi_assert(index != m_filterAllocated.end());
@@ -39,7 +39,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
DigitalGlitchFilter::~DigitalGlitchFilter() {
if (m_channelIndex >= 0) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_filterAllocated[m_channelIndex] = false;
}
}

View File

@@ -103,7 +103,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
return false;
}
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
if (button > m_joystickButtons[stick].count) {
// Unlock early so error printing isn't locked.
lock.unlock();
@@ -134,7 +134,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
return false;
}
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
if (button > m_joystickButtons[stick].count) {
// Unlock early so error printing isn't locked.
lock.unlock();
@@ -171,7 +171,7 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
return false;
}
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
if (button > m_joystickButtons[stick].count) {
// Unlock early so error printing isn't locked.
lock.unlock();
@@ -204,7 +204,7 @@ double DriverStation::GetStickAxis(int stick, int axis) {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
if (axis >= m_joystickAxes[stick].count) {
// Unlock early so error printing isn't locked.
m_cacheDataMutex.unlock();
@@ -230,7 +230,7 @@ int DriverStation::GetStickPOV(int stick, int pov) {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
if (pov >= m_joystickPOVs[stick].count) {
// Unlock early so error printing isn't locked.
lock.unlock();
@@ -256,7 +256,7 @@ int DriverStation::GetStickButtons(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_joystickButtons[stick].buttons;
}
@@ -271,7 +271,7 @@ int DriverStation::GetStickAxisCount(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_joystickAxes[stick].count;
}
@@ -286,7 +286,7 @@ int DriverStation::GetStickPOVCount(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_joystickPOVs[stick].count;
}
@@ -301,7 +301,7 @@ int DriverStation::GetStickButtonCount(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_joystickButtons[stick].count;
}
@@ -316,7 +316,7 @@ bool DriverStation::GetJoystickIsXbox(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return false;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return static_cast<bool>(m_joystickDescriptor[stick].isXbox);
}
@@ -331,7 +331,7 @@ int DriverStation::GetJoystickType(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return static_cast<int>(m_joystickDescriptor[stick].type);
}
@@ -345,7 +345,7 @@ std::string DriverStation::GetJoystickName(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
std::string retVal(m_joystickDescriptor[stick].name);
return retVal;
}
@@ -361,7 +361,7 @@ int DriverStation::GetJoystickAxisType(int stick, int axis) const {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_joystickDescriptor[stick].axisTypes[axis];
}
@@ -482,27 +482,27 @@ bool DriverStation::IsBrownedOut() const {
}
std::string DriverStation::GetGameSpecificMessage() const {
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_matchInfo->gameSpecificMessage;
}
std::string DriverStation::GetEventName() const {
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_matchInfo->eventName;
}
DriverStation::MatchType DriverStation::GetMatchType() const {
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_matchInfo->matchType;
}
int DriverStation::GetMatchNumber() const {
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_matchInfo->matchNumber;
}
int DriverStation::GetReplayNumber() const {
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
return m_matchInfo->replayNumber;
}
@@ -650,7 +650,7 @@ void DriverStation::GetData() {
UpdateControlWord(true, controlWord);
// Obtain a write lock on the data, swap the cached data into the
// main data arrays
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
for (int32_t i = 0; i < kJoystickPorts; i++) {
// If buttons weren't pressed and are now, set flags in m_buttonsPressed
@@ -768,7 +768,7 @@ void DriverStation::Run() {
void DriverStation::UpdateControlWord(bool force,
HAL_ControlWord& controlWord) const {
auto now = std::chrono::steady_clock::now();
std::lock_guard<std::mutex> lock(m_controlWordMutex);
std::lock_guard<wpi::mutex> lock(m_controlWordMutex);
// Update every 50 ms or on force.
if ((now - m_lastControlWordUpdate > std::chrono::milliseconds(50)) ||
force) {

View File

@@ -22,7 +22,7 @@
using namespace frc;
std::mutex ErrorBase::_globalErrorMutex;
wpi::mutex ErrorBase::_globalErrorMutex;
Error ErrorBase::_globalError;
ErrorBase::ErrorBase() { HAL_Initialize(500, 0); }
@@ -68,7 +68,7 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
m_error.Set(-1, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -97,7 +97,7 @@ void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
m_error.Set(success, err.str(), filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -122,7 +122,7 @@ void ErrorBase::SetError(Error::Code code, llvm::StringRef contextMessage,
m_error.Set(code, contextMessage, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -160,7 +160,7 @@ void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange,
delete[] buf;
// Update the global error if there is not one already set.
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -186,7 +186,7 @@ void ErrorBase::SetWPIError(llvm::StringRef errorMessage, Error::Code code,
m_error.Set(code, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -208,7 +208,7 @@ void ErrorBase::SetGlobalError(Error::Code code, llvm::StringRef contextMessage,
llvm::StringRef function, int lineNumber) {
// If there was an error
if (code != 0) {
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
// Set the current error information for this object.
_globalError.Set(code, contextMessage, filename, function, lineNumber,
@@ -222,7 +222,7 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
llvm::StringRef function, int lineNumber) {
std::string err = errorMessage.str() + ": " + contextMessage.str();
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() != 0) {
_globalError.Clear();
}
@@ -233,6 +233,6 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
* Retrieve the current global error.
*/
Error& ErrorBase::GetGlobalError() {
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
return _globalError;
}

View File

@@ -18,7 +18,7 @@
using namespace frc;
std::set<MotorSafetyHelper*> MotorSafetyHelper::m_helperList;
std::mutex MotorSafetyHelper::m_listMutex;
wpi::mutex MotorSafetyHelper::m_listMutex;
/**
* The constructor for a MotorSafetyHelper object.
@@ -38,12 +38,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
m_expiration = DEFAULT_SAFETY_EXPIRATION;
m_stopTime = Timer::GetFPGATimestamp();
std::lock_guard<std::mutex> sync(m_listMutex);
std::lock_guard<wpi::mutex> sync(m_listMutex);
m_helperList.insert(this);
}
MotorSafetyHelper::~MotorSafetyHelper() {
std::lock_guard<std::mutex> sync(m_listMutex);
std::lock_guard<wpi::mutex> sync(m_listMutex);
m_helperList.erase(this);
}
@@ -52,7 +52,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
* Resets the timer on this object that is used to do the timeouts.
*/
void MotorSafetyHelper::Feed() {
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
}
@@ -61,7 +61,7 @@ void MotorSafetyHelper::Feed() {
* @param expirationTime The timeout value in seconds.
*/
void MotorSafetyHelper::SetExpiration(double expirationTime) {
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
m_expiration = expirationTime;
}
@@ -70,7 +70,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
* @return the timeout value in seconds.
*/
double MotorSafetyHelper::GetExpiration() const {
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
return m_expiration;
}
@@ -80,7 +80,7 @@ double MotorSafetyHelper::GetExpiration() const {
* timed out.
*/
bool MotorSafetyHelper::IsAlive() const {
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
}
@@ -94,7 +94,7 @@ void MotorSafetyHelper::Check() {
DriverStation& ds = DriverStation::GetInstance();
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
if (m_stopTime < Timer::GetFPGATimestamp()) {
llvm::SmallString<128> buf;
llvm::raw_svector_ostream desc(buf);
@@ -111,7 +111,7 @@ void MotorSafetyHelper::Check() {
* @param enabled True if motor safety is enforced for this object
*/
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
m_enabled = enabled;
}
@@ -121,7 +121,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
* @return True if motor safety is enforced for this device
*/
bool MotorSafetyHelper::IsSafetyEnabled() const {
std::lock_guard<std::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> sync(m_syncMutex);
return m_enabled;
}
@@ -131,7 +131,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
* any that have timed out.
*/
void MotorSafetyHelper::CheckMotors() {
std::lock_guard<std::mutex> sync(m_listMutex);
std::lock_guard<wpi::mutex> sync(m_listMutex);
for (auto elem : m_helperList) {
elem->Check();
}

View File

@@ -15,7 +15,7 @@
using namespace frc;
std::mutex Notifier::m_destructorMutex;
wpi::mutex Notifier::m_destructorMutex;
/**
* Create a Notifier for timer event notification.
@@ -45,8 +45,8 @@ Notifier::~Notifier() {
/* Acquire the mutex; this makes certain that the handler is not being
* executed by the interrupt manager.
*/
std::lock_guard<std::mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<std::mutex> lock(m_processMutex);
std::lock_guard<wpi::mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<wpi::mutex> lock(m_processMutex);
}
/**
@@ -69,7 +69,7 @@ void Notifier::Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle) {
Notifier* notifier;
{
// Lock static mutex to grab the notifier param
std::lock_guard<std::mutex> lock(Notifier::m_destructorMutex);
std::lock_guard<wpi::mutex> lock(Notifier::m_destructorMutex);
int32_t status = 0;
auto notifierPointer = HAL_GetNotifierParam(handle, &status);
if (notifierPointer == nullptr) return;
@@ -96,7 +96,7 @@ void Notifier::Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle) {
* @param delay Seconds to wait before the handler is called.
*/
void Notifier::StartSingle(double delay) {
std::lock_guard<std::mutex> sync(m_processMutex);
std::lock_guard<wpi::mutex> sync(m_processMutex);
m_periodic = false;
m_period = delay;
m_expirationTime = GetClock() + m_period;
@@ -114,7 +114,7 @@ void Notifier::StartSingle(double delay) {
* after the call to this method.
*/
void Notifier::StartPeriodic(double period) {
std::lock_guard<std::mutex> sync(m_processMutex);
std::lock_guard<wpi::mutex> sync(m_processMutex);
m_periodic = true;
m_period = period;
m_expirationTime = GetClock() + m_period;
@@ -137,6 +137,6 @@ void Notifier::Stop() {
// Wait for a currently executing handler to complete before returning from
// Stop()
std::lock_guard<std::mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<std::mutex> lock(m_processMutex);
std::lock_guard<wpi::mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<wpi::mutex> lock(m_processMutex);
}

View File

@@ -91,7 +91,7 @@ void PIDController::Calculate() {
PIDOutput* pidOutput;
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
pidInput = m_pidInput;
pidOutput = m_pidOutput;
enabled = m_enabled;
@@ -103,7 +103,7 @@ void PIDController::Calculate() {
if (enabled) {
double feedForward = CalculateFeedForward();
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
double input = pidInput->PIDGet();
double result;
PIDOutput* pidOutput;
@@ -200,7 +200,7 @@ double PIDController::CalculateFeedForward() {
*/
void PIDController::SetPID(double p, double i, double d) {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -223,7 +223,7 @@ void PIDController::SetPID(double p, double i, double d) {
*/
void PIDController::SetPID(double p, double i, double d, double f) {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -242,7 +242,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
* @return proportional coefficient
*/
double PIDController::GetP() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_P;
}
@@ -252,7 +252,7 @@ double PIDController::GetP() const {
* @return integral coefficient
*/
double PIDController::GetI() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_I;
}
@@ -262,7 +262,7 @@ double PIDController::GetI() const {
* @return differential coefficient
*/
double PIDController::GetD() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_D;
}
@@ -272,7 +272,7 @@ double PIDController::GetD() const {
* @return Feed forward coefficient
*/
double PIDController::GetF() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_F;
}
@@ -284,7 +284,7 @@ double PIDController::GetF() const {
* @return the latest calculated output
*/
double PIDController::Get() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_result;
}
@@ -298,7 +298,7 @@ double PIDController::Get() const {
* @param continuous true turns on continuous, false turns off continuous
*/
void PIDController::SetContinuous(bool continuous) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_continuous = continuous;
}
@@ -310,7 +310,7 @@ void PIDController::SetContinuous(bool continuous) {
*/
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_minimumInput = minimumInput;
m_maximumInput = maximumInput;
}
@@ -325,7 +325,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
* @param maximumOutput the maximum value to write to the output
*/
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_minimumOutput = minimumOutput;
m_maximumOutput = maximumOutput;
}
@@ -339,7 +339,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
*/
void PIDController::SetSetpoint(double setpoint) {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
if (m_maximumInput > m_minimumInput) {
if (setpoint > m_maximumInput)
@@ -366,7 +366,7 @@ void PIDController::SetSetpoint(double setpoint) {
* @return the current setpoint
*/
double PIDController::GetSetpoint() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_setpoint;
}
@@ -376,7 +376,7 @@ double PIDController::GetSetpoint() const {
* @return the change in setpoint over time
*/
double PIDController::GetDeltaSetpoint() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
}
@@ -388,7 +388,7 @@ double PIDController::GetDeltaSetpoint() const {
double PIDController::GetError() const {
double setpoint = GetSetpoint();
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return GetContinuousError(setpoint - m_pidInput->PIDGet());
}
}
@@ -419,7 +419,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
double PIDController::GetAvgError() const {
double avgError = 0;
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
// Don't divide by zero.
if (m_buf.size()) avgError = m_bufTotal / m_buf.size();
}
@@ -433,7 +433,7 @@ double PIDController::GetAvgError() const {
* @param percentage error which is tolerable
*/
void PIDController::SetTolerance(double percent) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -445,7 +445,7 @@ void PIDController::SetTolerance(double percent) {
* @param percentage error which is tolerable
*/
void PIDController::SetAbsoluteTolerance(double absTolerance) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_toleranceType = kAbsoluteTolerance;
m_tolerance = absTolerance;
}
@@ -457,7 +457,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
* @param percentage error which is tolerable
*/
void PIDController::SetPercentTolerance(double percent) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -473,7 +473,7 @@ void PIDController::SetPercentTolerance(double percent) {
* @param bufLength Number of previous cycles to average. Defaults to 1.
*/
void PIDController::SetToleranceBuffer(int bufLength) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_bufLength = bufLength;
// Cut the buffer down to size if needed.
@@ -496,13 +496,13 @@ void PIDController::SetToleranceBuffer(int bufLength) {
*/
bool PIDController::OnTarget() const {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
if (m_buf.size() == 0) return false;
}
double error = GetAvgError();
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
switch (m_toleranceType) {
case kPercentTolerance:
return std::fabs(error) <
@@ -523,7 +523,7 @@ bool PIDController::OnTarget() const {
*/
void PIDController::Enable() {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_enabled = true;
}
@@ -535,7 +535,7 @@ void PIDController::Enable() {
*/
void PIDController::Disable() {
{
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_pidOutput->PIDWrite(0);
m_enabled = false;
}
@@ -547,7 +547,7 @@ void PIDController::Disable() {
* Return true if PIDController is enabled.
*/
bool PIDController::IsEnabled() const {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
return m_enabled;
}
@@ -557,7 +557,7 @@ bool PIDController::IsEnabled() const {
void PIDController::Reset() {
Disable();
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_prevError = 0;
m_totalError = 0;
m_result = 0;
@@ -586,7 +586,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_pListener = m_pEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_P = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
@@ -594,7 +594,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_iListener = m_iEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_I = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
@@ -602,7 +602,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_dListener = m_dEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_D = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
@@ -610,7 +610,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_fListener = m_fEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_F = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);

View File

@@ -12,7 +12,7 @@
using namespace frc;
std::mutex Resource::m_createMutex;
wpi::mutex Resource::m_createMutex;
/**
* Allocate storage for a new instance of Resource.
@@ -38,7 +38,7 @@ Resource::Resource(uint32_t elements) {
*/
void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
uint32_t elements) {
std::lock_guard<std::mutex> sync(m_createMutex);
std::lock_guard<wpi::mutex> sync(m_createMutex);
if (!r) {
r = std::make_unique<Resource>(elements);
}
@@ -52,7 +52,7 @@ void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
* allocated.
*/
uint32_t Resource::Allocate(const std::string& resourceDesc) {
std::lock_guard<std::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
if (!m_isAllocated[i]) {
m_isAllocated[i] = true;
@@ -70,7 +70,7 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
* verified unallocated, then returned.
*/
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
std::lock_guard<std::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
if (index >= m_isAllocated.size()) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
return std::numeric_limits<uint32_t>::max();
@@ -91,7 +91,7 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
* be reused somewhere else in the program.
*/
void Resource::Free(uint32_t index) {
std::unique_lock<std::mutex> sync(m_allocateMutex);
std::unique_lock<wpi::mutex> sync(m_allocateMutex);
if (index == std::numeric_limits<uint32_t>::max()) return;
if (index >= m_isAllocated.size()) {
wpi_setWPIError(NotAllocated);

View File

@@ -83,7 +83,7 @@ double Timer::Get() const {
double result;
double currentTime = GetFPGATimestamp();
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
if (m_running) {
// If the current time is before the start time, then the FPGA clock
// rolled over. Compensate by adding the ~71 minutes that it takes
@@ -107,7 +107,7 @@ double Timer::Get() const {
* now.
*/
void Timer::Reset() {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
}
@@ -119,7 +119,7 @@ void Timer::Reset() {
* relative to the system clock.
*/
void Timer::Start() {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
if (!m_running) {
m_startTime = GetFPGATimestamp();
m_running = true;
@@ -136,7 +136,7 @@ void Timer::Start() {
void Timer::Stop() {
double temp = Get();
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
if (m_running) {
m_accumulatedTime = temp;
m_running = false;
@@ -153,7 +153,7 @@ void Timer::Stop() {
*/
bool Timer::HasPeriodPassed(double period) {
if (Get() > period) {
std::lock_guard<std::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> sync(m_mutex);
// Advance the start time by the period.
m_startTime += period;
// Don't set it to the current time... we want to avoid drift.