mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Remove template types from lock RAII wrapper usages (#1756)
C++17 has template type autodeduction. These wrappers include std::lock_guard and std::unique_lock.
This commit is contained in:
committed by
Peter Johnson
parent
e582518bae
commit
841ef5d739
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -28,7 +28,7 @@ std::array<bool, 3> DigitalGlitchFilter::m_filterAllocated = {
|
||||
wpi::mutex DigitalGlitchFilter::m_mutex;
|
||||
|
||||
DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
auto index =
|
||||
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
|
||||
wpi_assert(index != m_filterAllocated.end());
|
||||
@@ -43,7 +43,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
|
||||
DigitalGlitchFilter::~DigitalGlitchFilter() {
|
||||
if (m_channelIndex >= 0) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_filterAllocated[m_channelIndex] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
"Joystick Button missing, check if all controllers are plugged in");
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<wpi::mutex> lock(m_buttonEdgeMutex);
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
// If button was pressed, clear flag and return true
|
||||
if (m_joystickButtonsPressed[stick] & 1 << (button - 1)) {
|
||||
m_joystickButtonsPressed[stick] &= ~(1 << (button - 1));
|
||||
@@ -175,7 +175,7 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
"Joystick Button missing, check if all controllers are plugged in");
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<wpi::mutex> lock(m_buttonEdgeMutex);
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
// If button was released, clear flag and return true
|
||||
if (m_joystickButtonsReleased[stick] & 1 << (button - 1)) {
|
||||
m_joystickButtonsReleased[stick] &= ~(1 << (button - 1));
|
||||
@@ -440,7 +440,7 @@ bool DriverStation::WaitForData(double timeout) {
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
std::unique_lock<wpi::mutex> lock(m_waitForDataMutex);
|
||||
std::unique_lock lock(m_waitForDataMutex);
|
||||
int currentCount = m_waitForDataCounter;
|
||||
while (m_waitForDataCounter == currentCount) {
|
||||
if (timeout > 0) {
|
||||
@@ -472,7 +472,7 @@ void DriverStation::GetData() {
|
||||
{
|
||||
// Compute the pressed and released buttons
|
||||
HAL_JoystickButtons currentButtons;
|
||||
std::unique_lock<wpi::mutex> lock(m_buttonEdgeMutex);
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
|
||||
for (int32_t i = 0; i < kJoystickPorts; i++) {
|
||||
HAL_GetJoystickButtons(i, ¤tButtons);
|
||||
@@ -490,7 +490,7 @@ void DriverStation::GetData() {
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> waitLock(m_waitForDataMutex);
|
||||
std::lock_guard waitLock(m_waitForDataMutex);
|
||||
// Nofify all threads
|
||||
m_waitForDataCounter++;
|
||||
m_waitForDataCond.notify_all();
|
||||
|
||||
@@ -40,13 +40,13 @@ GlobalErrors& GlobalErrors::GetInstance() {
|
||||
|
||||
void GlobalErrors::Insert(const Error& error) {
|
||||
GlobalErrors& inst = GetInstance();
|
||||
std::lock_guard<wpi::mutex> lock(inst.mutex);
|
||||
std::lock_guard lock(inst.mutex);
|
||||
inst.lastError = &(*inst.errors.insert(error).first);
|
||||
}
|
||||
|
||||
void GlobalErrors::Insert(Error&& error) {
|
||||
GlobalErrors& inst = GetInstance();
|
||||
std::lock_guard<wpi::mutex> lock(inst.mutex);
|
||||
std::lock_guard lock(inst.mutex);
|
||||
inst.lastError = &(*inst.errors.insert(std::move(error)).first);
|
||||
}
|
||||
|
||||
@@ -165,14 +165,14 @@ void ErrorBase::SetGlobalWPIError(const wpi::Twine& errorMessage,
|
||||
|
||||
Error ErrorBase::GetGlobalError() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::lock_guard<wpi::mutex> mutex(inst.mutex);
|
||||
std::lock_guard mutex(inst.mutex);
|
||||
if (!inst.lastError) return Error{};
|
||||
return *inst.lastError;
|
||||
}
|
||||
|
||||
std::vector<Error> ErrorBase::GetGlobalErrors() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::lock_guard<wpi::mutex> mutex(inst.mutex);
|
||||
std::lock_guard mutex(inst.mutex);
|
||||
std::vector<Error> rv;
|
||||
for (auto&& error : inst.errors) rv.push_back(error);
|
||||
return rv;
|
||||
@@ -180,7 +180,7 @@ std::vector<Error> ErrorBase::GetGlobalErrors() {
|
||||
|
||||
void ErrorBase::ClearGlobalErrors() {
|
||||
auto& inst = GlobalErrors::GetInstance();
|
||||
std::lock_guard<wpi::mutex> mutex(inst.mutex);
|
||||
std::lock_guard mutex(inst.mutex);
|
||||
inst.errors.clear();
|
||||
inst.lastError = nullptr;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ static wpi::SmallPtrSet<MotorSafety*, 32> instanceList;
|
||||
static wpi::mutex listMutex;
|
||||
|
||||
MotorSafety::MotorSafety() {
|
||||
std::lock_guard<wpi::mutex> lock(listMutex);
|
||||
std::lock_guard lock(listMutex);
|
||||
instanceList.insert(this);
|
||||
}
|
||||
|
||||
MotorSafety::~MotorSafety() {
|
||||
std::lock_guard<wpi::mutex> lock(listMutex);
|
||||
std::lock_guard lock(listMutex);
|
||||
instanceList.erase(this);
|
||||
}
|
||||
|
||||
@@ -51,32 +51,32 @@ MotorSafety& MotorSafety::operator=(MotorSafety&& rhs) {
|
||||
}
|
||||
|
||||
void MotorSafety::Feed() {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
|
||||
}
|
||||
|
||||
void MotorSafety::SetExpiration(double expirationTime) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_expiration = expirationTime;
|
||||
}
|
||||
|
||||
double MotorSafety::GetExpiration() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_expiration;
|
||||
}
|
||||
|
||||
bool MotorSafety::IsAlive() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
|
||||
}
|
||||
|
||||
void MotorSafety::SetSafetyEnabled(bool enabled) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
bool MotorSafety::IsSafetyEnabled() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ void MotorSafety::Check() {
|
||||
double stopTime;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
enabled = m_enabled;
|
||||
stopTime = m_stopTime;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ void MotorSafety::Check() {
|
||||
}
|
||||
|
||||
void MotorSafety::CheckMotors() {
|
||||
std::lock_guard<wpi::mutex> lock(listMutex);
|
||||
std::lock_guard lock(listMutex);
|
||||
for (auto elem : instanceList) {
|
||||
elem->Check();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -35,7 +35,7 @@ Notifier::Notifier(TimerEventHandler handler) {
|
||||
|
||||
TimerEventHandler handler;
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
std::lock_guard lock(m_processMutex);
|
||||
handler = m_handler;
|
||||
if (m_periodic) {
|
||||
m_expirationTime += m_period;
|
||||
@@ -91,12 +91,12 @@ Notifier& Notifier::operator=(Notifier&& rhs) {
|
||||
}
|
||||
|
||||
void Notifier::SetHandler(TimerEventHandler handler) {
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
std::lock_guard lock(m_processMutex);
|
||||
m_handler = handler;
|
||||
}
|
||||
|
||||
void Notifier::StartSingle(double delay) {
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
std::lock_guard lock(m_processMutex);
|
||||
m_periodic = false;
|
||||
m_period = delay;
|
||||
m_expirationTime = Timer::GetFPGATimestamp() + m_period;
|
||||
@@ -104,7 +104,7 @@ void Notifier::StartSingle(double delay) {
|
||||
}
|
||||
|
||||
void Notifier::StartPeriodic(double period) {
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
std::lock_guard lock(m_processMutex);
|
||||
m_periodic = true;
|
||||
m_period = period;
|
||||
m_expirationTime = Timer::GetFPGATimestamp() + m_period;
|
||||
|
||||
@@ -48,18 +48,18 @@ PIDBase::PIDBase(double Kp, double Ki, double Kd, double Kf, PIDSource& source,
|
||||
}
|
||||
|
||||
double PIDBase::Get() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_result;
|
||||
}
|
||||
|
||||
void PIDBase::SetContinuous(bool continuous) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_continuous = continuous;
|
||||
}
|
||||
|
||||
void PIDBase::SetInputRange(double minimumInput, double maximumInput) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_minimumInput = minimumInput;
|
||||
m_maximumInput = maximumInput;
|
||||
m_inputRange = maximumInput - minimumInput;
|
||||
@@ -69,14 +69,14 @@ void PIDBase::SetInputRange(double minimumInput, double maximumInput) {
|
||||
}
|
||||
|
||||
void PIDBase::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_minimumOutput = minimumOutput;
|
||||
m_maximumOutput = maximumOutput;
|
||||
}
|
||||
|
||||
void PIDBase::SetPID(double p, double i, double d) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -84,7 +84,7 @@ void PIDBase::SetPID(double p, double i, double d) {
|
||||
}
|
||||
|
||||
void PIDBase::SetPID(double p, double i, double d, double f) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -92,48 +92,48 @@ void PIDBase::SetPID(double p, double i, double d, double f) {
|
||||
}
|
||||
|
||||
void PIDBase::SetP(double p) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_P = p;
|
||||
}
|
||||
|
||||
void PIDBase::SetI(double i) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_I = i;
|
||||
}
|
||||
|
||||
void PIDBase::SetD(double d) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_D = d;
|
||||
}
|
||||
|
||||
void PIDBase::SetF(double f) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_F = f;
|
||||
}
|
||||
|
||||
double PIDBase::GetP() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_P;
|
||||
}
|
||||
|
||||
double PIDBase::GetI() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_I;
|
||||
}
|
||||
|
||||
double PIDBase::GetD() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_D;
|
||||
}
|
||||
|
||||
double PIDBase::GetF() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_F;
|
||||
}
|
||||
|
||||
void PIDBase::SetSetpoint(double setpoint) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
if (setpoint > m_maximumInput)
|
||||
@@ -149,19 +149,19 @@ void PIDBase::SetSetpoint(double setpoint) {
|
||||
}
|
||||
|
||||
double PIDBase::GetSetpoint() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
double PIDBase::GetDeltaSetpoint() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
|
||||
}
|
||||
|
||||
double PIDBase::GetError() const {
|
||||
double setpoint = GetSetpoint();
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return GetContinuousError(setpoint - m_pidInput->PIDGet());
|
||||
}
|
||||
}
|
||||
@@ -177,32 +177,32 @@ PIDSourceType PIDBase::GetPIDSourceType() const {
|
||||
}
|
||||
|
||||
void PIDBase::SetTolerance(double percent) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
|
||||
void PIDBase::SetAbsoluteTolerance(double absTolerance) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_toleranceType = kAbsoluteTolerance;
|
||||
m_tolerance = absTolerance;
|
||||
}
|
||||
|
||||
void PIDBase::SetPercentTolerance(double percent) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
|
||||
void PIDBase::SetToleranceBuffer(int bufLength) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_filter = LinearFilter::MovingAverage(bufLength);
|
||||
}
|
||||
|
||||
bool PIDBase::OnTarget() const {
|
||||
double error = GetError();
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
switch (m_toleranceType) {
|
||||
case kPercentTolerance:
|
||||
return std::fabs(error) < m_tolerance / 100 * m_inputRange;
|
||||
@@ -218,7 +218,7 @@ bool PIDBase::OnTarget() const {
|
||||
}
|
||||
|
||||
void PIDBase::Reset() {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_prevError = 0;
|
||||
m_totalError = 0;
|
||||
m_result = 0;
|
||||
@@ -246,7 +246,7 @@ void PIDBase::Calculate() {
|
||||
|
||||
bool enabled;
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
enabled = m_enabled;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ void PIDBase::Calculate() {
|
||||
double totalError;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
|
||||
input = m_filter.Calculate(m_pidInput->PIDGet());
|
||||
|
||||
@@ -308,8 +308,8 @@ void PIDBase::Calculate() {
|
||||
|
||||
{
|
||||
// Ensures m_enabled check and PIDWrite() call occur atomically
|
||||
std::lock_guard<wpi::mutex> pidWriteLock(m_pidWriteMutex);
|
||||
std::unique_lock<wpi::mutex> mainLock(m_thisMutex);
|
||||
std::lock_guard pidWriteLock(m_pidWriteMutex);
|
||||
std::unique_lock mainLock(m_thisMutex);
|
||||
if (m_enabled) {
|
||||
// Don't block other PIDBase operations on PIDWrite()
|
||||
mainLock.unlock();
|
||||
@@ -318,7 +318,7 @@ void PIDBase::Calculate() {
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_prevError = m_error;
|
||||
m_error = error;
|
||||
m_totalError = totalError;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -41,7 +41,7 @@ PIDController::~PIDController() {
|
||||
|
||||
void PIDController::Enable() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,9 @@ void PIDController::Enable() {
|
||||
void PIDController::Disable() {
|
||||
{
|
||||
// Ensures m_enabled modification and PIDWrite() call occur atomically
|
||||
std::lock_guard<wpi::mutex> pidWriteLock(m_pidWriteMutex);
|
||||
std::lock_guard pidWriteLock(m_pidWriteMutex);
|
||||
{
|
||||
std::lock_guard<wpi::mutex> mainLock(m_thisMutex);
|
||||
std::lock_guard mainLock(m_thisMutex);
|
||||
m_enabled = false;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ void PIDController::SetEnabled(bool enable) {
|
||||
}
|
||||
|
||||
bool PIDController::IsEnabled() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -16,7 +16,7 @@ wpi::mutex Resource::m_createMutex;
|
||||
|
||||
void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
|
||||
uint32_t elements) {
|
||||
std::lock_guard<wpi::mutex> lock(m_createMutex);
|
||||
std::lock_guard lock(m_createMutex);
|
||||
if (!r) {
|
||||
r = std::make_unique<Resource>(elements);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ Resource::Resource(uint32_t elements) {
|
||||
}
|
||||
|
||||
uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
std::lock_guard lock(m_allocateMutex);
|
||||
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
|
||||
if (!m_isAllocated[i]) {
|
||||
m_isAllocated[i] = true;
|
||||
@@ -39,7 +39,7 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
}
|
||||
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
std::lock_guard lock(m_allocateMutex);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
return std::numeric_limits<uint32_t>::max();
|
||||
@@ -53,7 +53,7 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
}
|
||||
|
||||
void Resource::Free(uint32_t index) {
|
||||
std::unique_lock<wpi::mutex> lock(m_allocateMutex);
|
||||
std::unique_lock lock(m_allocateMutex);
|
||||
if (index == std::numeric_limits<uint32_t>::max()) return;
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
|
||||
@@ -28,7 +28,7 @@ class SPI::Accumulator {
|
||||
Accumulator(HAL_SPIPort port, int xferSize, int validMask, int validValue,
|
||||
int dataShift, int dataSize, bool isSigned, bool bigEndian)
|
||||
: m_notifier([=]() {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
Update();
|
||||
}),
|
||||
m_buf(new uint32_t[(xferSize + 1) * kAccumulateDepth]),
|
||||
@@ -356,7 +356,7 @@ void SPI::FreeAccumulator() {
|
||||
|
||||
void SPI::ResetAccumulator() {
|
||||
if (!m_accum) return;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->m_value = 0;
|
||||
m_accum->m_count = 0;
|
||||
m_accum->m_lastValue = 0;
|
||||
@@ -366,40 +366,40 @@ void SPI::ResetAccumulator() {
|
||||
|
||||
void SPI::SetAccumulatorCenter(int center) {
|
||||
if (!m_accum) return;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->m_center = center;
|
||||
}
|
||||
|
||||
void SPI::SetAccumulatorDeadband(int deadband) {
|
||||
if (!m_accum) return;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->m_deadband = deadband;
|
||||
}
|
||||
|
||||
int SPI::GetAccumulatorLastValue() const {
|
||||
if (!m_accum) return 0;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_lastValue;
|
||||
}
|
||||
|
||||
int64_t SPI::GetAccumulatorValue() const {
|
||||
if (!m_accum) return 0;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_value;
|
||||
}
|
||||
|
||||
int64_t SPI::GetAccumulatorCount() const {
|
||||
if (!m_accum) return 0;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_count;
|
||||
}
|
||||
|
||||
double SPI::GetAccumulatorAverage() const {
|
||||
if (!m_accum) return 0;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
if (m_accum->m_count == 0) return 0.0;
|
||||
return static_cast<double>(m_accum->m_value) / m_accum->m_count;
|
||||
@@ -411,7 +411,7 @@ void SPI::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
count = 0;
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
value = m_accum->m_value;
|
||||
count = m_accum->m_count;
|
||||
@@ -419,20 +419,20 @@ void SPI::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
|
||||
void SPI::SetAccumulatorIntegratedCenter(double center) {
|
||||
if (!m_accum) return;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->m_integratedCenter = center;
|
||||
}
|
||||
|
||||
double SPI::GetAccumulatorIntegratedValue() const {
|
||||
if (!m_accum) return 0;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
return m_accum->m_integratedValue;
|
||||
}
|
||||
|
||||
double SPI::GetAccumulatorIntegratedAverage() const {
|
||||
if (!m_accum) return 0;
|
||||
std::lock_guard<wpi::mutex> lock(m_accum->m_mutex);
|
||||
std::lock_guard lock(m_accum->m_mutex);
|
||||
m_accum->Update();
|
||||
if (m_accum->m_count <= 1) return 0.0;
|
||||
// count-1 due to not integrating the first value received
|
||||
|
||||
@@ -58,7 +58,7 @@ double Timer::Get() const {
|
||||
double result;
|
||||
double currentTime = GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(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 to roll over to
|
||||
@@ -76,13 +76,13 @@ double Timer::Get() const {
|
||||
}
|
||||
|
||||
void Timer::Reset() {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_accumulatedTime = 0;
|
||||
m_startTime = GetFPGATimestamp();
|
||||
}
|
||||
|
||||
void Timer::Start() {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
if (!m_running) {
|
||||
m_startTime = GetFPGATimestamp();
|
||||
m_running = true;
|
||||
@@ -92,7 +92,7 @@ void Timer::Start() {
|
||||
void Timer::Stop() {
|
||||
double temp = Get();
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
if (m_running) {
|
||||
m_accumulatedTime = temp;
|
||||
m_running = false;
|
||||
@@ -101,7 +101,7 @@ void Timer::Stop() {
|
||||
|
||||
bool Timer::HasPeriodPassed(double period) {
|
||||
if (Get() > period) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(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.
|
||||
|
||||
@@ -32,7 +32,7 @@ class Watchdog::Thread : public wpi::SafeThread {
|
||||
};
|
||||
|
||||
void Watchdog::Thread::Main() {
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
|
||||
while (m_active) {
|
||||
if (m_watchdogs.size() > 0) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2011-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -51,7 +51,7 @@ Scheduler* Scheduler::GetInstance() {
|
||||
}
|
||||
|
||||
void Scheduler::AddCommand(Command* command) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->additionsMutex);
|
||||
std::lock_guard lock(m_impl->additionsMutex);
|
||||
if (std::find(m_impl->additions.begin(), m_impl->additions.end(), command) !=
|
||||
m_impl->additions.end())
|
||||
return;
|
||||
@@ -59,7 +59,7 @@ void Scheduler::AddCommand(Command* command) {
|
||||
}
|
||||
|
||||
void Scheduler::AddButton(ButtonScheduler* button) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->buttonsMutex);
|
||||
std::lock_guard lock(m_impl->buttonsMutex);
|
||||
m_impl->buttons.emplace_back(button);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ void Scheduler::Run() {
|
||||
{
|
||||
if (!m_impl->enabled) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->buttonsMutex);
|
||||
std::lock_guard lock(m_impl->buttonsMutex);
|
||||
for (auto& button : m_impl->buttons) {
|
||||
button->Execute();
|
||||
}
|
||||
@@ -103,7 +103,7 @@ void Scheduler::Run() {
|
||||
|
||||
// Add the new things
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->additionsMutex);
|
||||
std::lock_guard lock(m_impl->additionsMutex);
|
||||
for (auto& addition : m_impl->additions) {
|
||||
// Check to make sure no adding during adding
|
||||
if (m_impl->adding) {
|
||||
|
||||
@@ -73,44 +73,44 @@ PIDController& PIDController::operator=(PIDController&& rhs) {
|
||||
}
|
||||
|
||||
void PIDController::SetP(double Kp) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_Kp = Kp;
|
||||
}
|
||||
|
||||
void PIDController::SetI(double Ki) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_Ki = Ki;
|
||||
}
|
||||
|
||||
void PIDController::SetD(double Kd) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_Kd = Kd;
|
||||
}
|
||||
|
||||
double PIDController::GetP() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_Kp;
|
||||
}
|
||||
|
||||
double PIDController::GetI() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_Ki;
|
||||
}
|
||||
|
||||
double PIDController::GetD() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_Kd;
|
||||
}
|
||||
|
||||
double PIDController::GetPeriod() const { return m_period; }
|
||||
|
||||
double PIDController::GetOutput() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
void PIDController::SetSetpoint(double setpoint) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
m_setpoint = std::clamp(setpoint, m_minimumInput, m_maximumInput);
|
||||
@@ -120,7 +120,7 @@ void PIDController::SetSetpoint(double setpoint) {
|
||||
}
|
||||
|
||||
double PIDController::GetSetpoint() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ bool PIDController::AtSetpoint(double tolerance, double deltaTolerance,
|
||||
Tolerance toleranceType) const {
|
||||
double deltaError = GetDeltaError();
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
if (toleranceType == Tolerance::kPercent) {
|
||||
return std::abs(m_currError) < tolerance / 100 * m_inputRange &&
|
||||
std::abs(deltaError) < deltaTolerance / 100 * m_inputRange;
|
||||
@@ -143,12 +143,12 @@ bool PIDController::AtSetpoint() const {
|
||||
}
|
||||
|
||||
void PIDController::SetContinuous(bool continuous) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_continuous = continuous;
|
||||
}
|
||||
|
||||
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_minimumInput = minimumInput;
|
||||
m_maximumInput = maximumInput;
|
||||
m_inputRange = maximumInput - minimumInput;
|
||||
@@ -160,14 +160,14 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
}
|
||||
|
||||
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_minimumOutput = minimumOutput;
|
||||
m_maximumOutput = maximumOutput;
|
||||
}
|
||||
|
||||
void PIDController::SetAbsoluteTolerance(double tolerance,
|
||||
double deltaTolerance) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_toleranceType = Tolerance::kAbsolute;
|
||||
m_tolerance = tolerance;
|
||||
m_deltaTolerance = deltaTolerance;
|
||||
@@ -175,14 +175,14 @@ void PIDController::SetAbsoluteTolerance(double tolerance,
|
||||
|
||||
void PIDController::SetPercentTolerance(double tolerance,
|
||||
double deltaTolerance) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_toleranceType = Tolerance::kPercent;
|
||||
m_tolerance = tolerance;
|
||||
m_deltaTolerance = deltaTolerance;
|
||||
}
|
||||
|
||||
double PIDController::GetError() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return GetContinuousError(m_currError);
|
||||
}
|
||||
|
||||
@@ -192,17 +192,17 @@ double PIDController::GetError() const {
|
||||
* @return The change in error per second.
|
||||
*/
|
||||
double PIDController::GetDeltaError() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return (m_currError - m_prevError) / GetPeriod();
|
||||
}
|
||||
|
||||
double PIDController::Calculate(double measurement) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return CalculateUnsafe(measurement);
|
||||
}
|
||||
|
||||
double PIDController::Calculate(double measurement, double setpoint) {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
|
||||
// Set setpoint to provided value
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
@@ -215,7 +215,7 @@ double PIDController::Calculate(double measurement, double setpoint) {
|
||||
}
|
||||
|
||||
void PIDController::Reset() {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_prevError = 0;
|
||||
m_totalError = 0;
|
||||
m_output = 0;
|
||||
|
||||
@@ -25,16 +25,16 @@ PIDControllerRunner::PIDControllerRunner(
|
||||
PIDControllerRunner::~PIDControllerRunner() { Disable(); }
|
||||
|
||||
void PIDControllerRunner::Enable() {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
m_enabled = true;
|
||||
}
|
||||
|
||||
void PIDControllerRunner::Disable() {
|
||||
// Ensures m_enabled modification and m_controllerOutput() call occur
|
||||
// atomically
|
||||
std::lock_guard<wpi::mutex> outputLock(m_outputMutex);
|
||||
std::lock_guard outputLock(m_outputMutex);
|
||||
{
|
||||
std::lock_guard<wpi::mutex> mainLock(m_thisMutex);
|
||||
std::lock_guard mainLock(m_thisMutex);
|
||||
m_enabled = false;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ void PIDControllerRunner::Disable() {
|
||||
}
|
||||
|
||||
bool PIDControllerRunner::IsEnabled() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
std::lock_guard lock(m_thisMutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void PIDControllerRunner::Run() {
|
||||
// Ensures m_enabled check and m_controllerOutput() call occur atomically
|
||||
std::lock_guard<wpi::mutex> outputLock(m_outputMutex);
|
||||
std::unique_lock<wpi::mutex> mainLock(m_thisMutex);
|
||||
std::lock_guard outputLock(m_outputMutex);
|
||||
std::unique_lock mainLock(m_thisMutex);
|
||||
if (m_enabled) {
|
||||
// Don't block other PIDControllerRunner operations on output
|
||||
mainLock.unlock();
|
||||
|
||||
@@ -61,7 +61,7 @@ LiveWindow* LiveWindow::GetInstance() {
|
||||
}
|
||||
|
||||
void LiveWindow::Add(std::shared_ptr<Sendable> sendable) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
auto& comp = m_impl->components[sendable.get()];
|
||||
comp.sendable = sendable;
|
||||
}
|
||||
@@ -75,19 +75,19 @@ void LiveWindow::AddChild(Sendable* parent, std::shared_ptr<Sendable> child) {
|
||||
}
|
||||
|
||||
void LiveWindow::AddChild(Sendable* parent, void* child) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
auto& comp = m_impl->components[child];
|
||||
comp.parent = parent;
|
||||
comp.telemetryEnabled = false;
|
||||
}
|
||||
|
||||
void LiveWindow::Remove(Sendable* sendable) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
m_impl->components.erase(sendable);
|
||||
}
|
||||
|
||||
void LiveWindow::EnableTelemetry(Sendable* sendable) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
// Re-enable global setting in case DisableAllTelemetry() was called.
|
||||
m_impl->telemetryEnabled = true;
|
||||
auto i = m_impl->components.find(sendable);
|
||||
@@ -95,24 +95,24 @@ void LiveWindow::EnableTelemetry(Sendable* sendable) {
|
||||
}
|
||||
|
||||
void LiveWindow::DisableTelemetry(Sendable* sendable) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
auto i = m_impl->components.find(sendable);
|
||||
if (i != m_impl->components.end()) i->getSecond().telemetryEnabled = false;
|
||||
}
|
||||
|
||||
void LiveWindow::DisableAllTelemetry() {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
m_impl->telemetryEnabled = false;
|
||||
for (auto& i : m_impl->components) i.getSecond().telemetryEnabled = false;
|
||||
}
|
||||
|
||||
bool LiveWindow::IsEnabled() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
return m_impl->liveWindowEnabled;
|
||||
}
|
||||
|
||||
void LiveWindow::SetEnabled(bool enabled) {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
if (m_impl->liveWindowEnabled == enabled) return;
|
||||
Scheduler* scheduler = Scheduler::GetInstance();
|
||||
m_impl->startLiveWindow = enabled;
|
||||
@@ -132,7 +132,7 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
}
|
||||
|
||||
void LiveWindow::UpdateValues() {
|
||||
std::lock_guard<wpi::mutex> lock(m_impl->mutex);
|
||||
std::lock_guard lock(m_impl->mutex);
|
||||
UpdateValuesUnsafe();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -34,22 +34,22 @@ SendableBase& SendableBase::operator=(SendableBase&& rhs) {
|
||||
}
|
||||
|
||||
std::string SendableBase::GetName() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void SendableBase::SetName(const wpi::Twine& name) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_name = name.str();
|
||||
}
|
||||
|
||||
std::string SendableBase::GetSubsystem() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
return m_subsystem;
|
||||
}
|
||||
|
||||
void SendableBase::SetSubsystem(const wpi::Twine& subsystem) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_subsystem = subsystem.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2011-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -97,7 +97,7 @@ void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
|
||||
return;
|
||||
}
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
||||
std::lock_guard lock(inst.tablesToDataMutex);
|
||||
auto& sddata = inst.tablesToData[key];
|
||||
if (!sddata.sendable || sddata.sendable != data) {
|
||||
sddata = SmartDashboardData(data);
|
||||
@@ -120,7 +120,7 @@ void SmartDashboard::PutData(Sendable* value) {
|
||||
|
||||
Sendable* SmartDashboard::GetData(wpi::StringRef key) {
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
||||
std::lock_guard lock(inst.tablesToDataMutex);
|
||||
auto data = inst.tablesToData.find(key);
|
||||
if (data == inst.tablesToData.end()) {
|
||||
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
|
||||
@@ -256,7 +256,7 @@ std::shared_ptr<nt::Value> SmartDashboard::GetValue(wpi::StringRef keyName) {
|
||||
|
||||
void SmartDashboard::UpdateValues() {
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
||||
std::lock_guard lock(inst.tablesToDataMutex);
|
||||
for (auto& i : inst.tablesToData) {
|
||||
i.getValue().builder.UpdateTable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user