mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Replaced instances of std::unique_lock with std::lock_guard where possible
If a lock is used with a mutex that doesn't need to be unlocked again before the lock is destroyed, std::lock_guard can be more efficient than std::unique_lock due to less overhead. This commit also removes a redundant set of curly braces in PIDController.cpp intended to constrain a lock's scope. Change-Id: Idd692ce439528ddb319a4c62c40c7351a664eb97
This commit is contained in:
committed by
Brad Miller (WPI)
parent
f64b055499
commit
c0ecde302f
@@ -41,7 +41,7 @@ bool analogSystemInitialized = false;
|
||||
* Initialize the analog System.
|
||||
*/
|
||||
void initializeAnalog(int32_t *status) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(analogRegisterWindowMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(analogRegisterWindowMutex);
|
||||
if (analogSystemInitialized) return;
|
||||
analogInputSystem = tAI::create(status);
|
||||
analogOutputSystem = tAO::create(status);
|
||||
@@ -265,7 +265,7 @@ int16_t getAnalogValue(void* analog_port_pointer, int32_t *status) {
|
||||
readSelect.Averaged = false;
|
||||
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(analogRegisterWindowMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(analogRegisterWindowMutex);
|
||||
analogInputSystem->writeReadSelect(readSelect, status);
|
||||
analogInputSystem->strobeLatchOutput(status);
|
||||
value = (int16_t) analogInputSystem->readOutput(status);
|
||||
@@ -296,7 +296,7 @@ int32_t getAnalogAverageValue(void* analog_port_pointer, int32_t *status) {
|
||||
readSelect.Averaged = true;
|
||||
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(analogRegisterWindowMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(analogRegisterWindowMutex);
|
||||
analogInputSystem->writeReadSelect(readSelect, status);
|
||||
analogInputSystem->strobeLatchOutput(status);
|
||||
value = (int32_t) analogInputSystem->readOutput(status);
|
||||
|
||||
Reference in New Issue
Block a user