mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +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
@@ -32,7 +32,7 @@ Notifier::Notifier(TimerEventHandler handler, void *param)
|
||||
m_nextEvent = nullptr;
|
||||
m_queued = false;
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
// do the first time intialization of static variables
|
||||
if (refcount == 0)
|
||||
{
|
||||
@@ -50,7 +50,7 @@ Notifier::Notifier(TimerEventHandler handler, void *param)
|
||||
Notifier::~Notifier()
|
||||
{
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
DeleteFromQueue();
|
||||
|
||||
// Delete the static variables when the last one is going away
|
||||
@@ -63,7 +63,7 @@ Notifier::~Notifier()
|
||||
|
||||
// Acquire the semaphore; this makes certain that the handler is
|
||||
// not being executed by the interrupt manager.
|
||||
std::unique_lock<priority_mutex> lock(m_handlerMutex);
|
||||
std::lock_guard<priority_mutex> lock(m_handlerMutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ void Notifier::ProcessQueue(uint32_t mask, void *params)
|
||||
while (true) // keep processing past events until no more
|
||||
{
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
double currentTime = GetClock();
|
||||
current = timerQueueHead;
|
||||
if (current == nullptr || current->m_expirationTime > currentTime)
|
||||
@@ -118,7 +118,7 @@ void Notifier::ProcessQueue(uint32_t mask, void *params)
|
||||
current->m_handlerMutex.unlock();
|
||||
}
|
||||
// reschedule the first item in the queue
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
UpdateAlarm();
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ void Notifier::DeleteFromQueue()
|
||||
*/
|
||||
void Notifier::StartSingle(double delay)
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
m_periodic = false;
|
||||
m_period = delay;
|
||||
DeleteFromQueue();
|
||||
@@ -224,7 +224,7 @@ void Notifier::StartSingle(double delay)
|
||||
*/
|
||||
void Notifier::StartPeriodic(double period)
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
m_periodic = true;
|
||||
m_period = period;
|
||||
DeleteFromQueue();
|
||||
@@ -241,11 +241,11 @@ void Notifier::StartPeriodic(double period)
|
||||
void Notifier::Stop()
|
||||
{
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
DeleteFromQueue();
|
||||
}
|
||||
// Wait for a currently executing handler to complete before returning from Stop()
|
||||
std::unique_lock<priority_mutex> sync(m_handlerMutex);
|
||||
std::lock_guard<priority_mutex> sync(m_handlerMutex);
|
||||
}
|
||||
|
||||
void Notifier::Run() {
|
||||
|
||||
Reference in New Issue
Block a user