mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00: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
@@ -11,7 +11,7 @@ Semaphore::Semaphore(uint32_t count) {
|
||||
}
|
||||
|
||||
void Semaphore::give() {
|
||||
std::unique_lock<priority_mutex> lock(m_mutex);
|
||||
std::lock_guard<priority_mutex> lock(m_mutex);
|
||||
++m_count;
|
||||
m_condition.notify_one();
|
||||
}
|
||||
@@ -23,7 +23,7 @@ void Semaphore::take() {
|
||||
}
|
||||
|
||||
bool Semaphore::tryTake() {
|
||||
std::unique_lock<priority_mutex> lock(m_mutex);
|
||||
std::lock_guard<priority_mutex> lock(m_mutex);
|
||||
if (m_count) {
|
||||
--m_count;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user