mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11: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) 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. */
|
||||
@@ -77,7 +77,7 @@ void UnsafeManipulateDIO(HAL_DigitalHandle handle, int32_t* status,
|
||||
tDIO* dSys = detail::UnsafeGetDigialSystem();
|
||||
auto mask = detail::ComputeDigitalMask(handle, status);
|
||||
if (status != 0) return;
|
||||
std::lock_guard<wpi::mutex> lock(dioMutex);
|
||||
std::lock_guard lock(dioMutex);
|
||||
|
||||
tDIO::tOutputEnable enableOE = dSys->readOutputEnable(status);
|
||||
enableOE.value |= mask;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-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. */
|
||||
@@ -59,7 +59,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// check for allocation, otherwise allocate and return a valid handle
|
||||
if (m_structures[index] != nullptr) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -77,7 +77,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -90,14 +90,14 @@ void DigitalHandleResource<THandle, TStruct, size>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size>
|
||||
void DigitalHandleResource<THandle, TStruct, size>::ResetHandles() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-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. */
|
||||
@@ -66,7 +66,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// check for allocation, otherwise allocate and return a valid handle
|
||||
if (m_structures[index] != nullptr) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -86,7 +86,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -100,7 +100,7 @@ void IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
void IndexedClassedHandleResource<THandle, TStruct, size,
|
||||
enumValue>::ResetHandles() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-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. */
|
||||
@@ -61,7 +61,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// check for allocation, otherwise allocate and return a valid handle
|
||||
if (m_structures[index] != nullptr) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -80,7 +80,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -94,7 +94,7 @@ void IndexedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
void IndexedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-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. */
|
||||
@@ -58,12 +58,12 @@ THandle
|
||||
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
std::shared_ptr<TStruct> toSet) {
|
||||
// globally lock to loop through indices
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
std::lock_guard lock(m_allocateMutex);
|
||||
for (int16_t i = 0; i < size; i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
// if a false index is found, grab its specific mutex
|
||||
// and allocate it.
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i] = toSet;
|
||||
return static_cast<THandle>(createHandle(i, enumValue, m_version));
|
||||
}
|
||||
@@ -81,7 +81,7 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -95,8 +95,8 @@ void LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
std::lock_guard handleLock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
void LimitedClassedHandleResource<THandle, TStruct, size,
|
||||
enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
|
||||
std::lock_guard handleLock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-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. */
|
||||
@@ -54,12 +54,12 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
|
||||
// globally lock to loop through indices
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
std::lock_guard lock(m_allocateMutex);
|
||||
for (int16_t i = 0; i < size; i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
// if a false index is found, grab its specific mutex
|
||||
// and allocate it.
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i] = std::make_shared<TStruct>();
|
||||
return static_cast<THandle>(createHandle(i, enumValue, m_version));
|
||||
}
|
||||
@@ -76,7 +76,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -90,8 +90,8 @@ void LimitedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
std::lock_guard handleLock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
void LimitedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
|
||||
std::lock_guard handleLock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
@@ -63,7 +63,7 @@ class UnlimitedHandleResource : public HandleBase {
|
||||
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
|
||||
std::shared_ptr<TStruct> structure) {
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
size_t i;
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
@@ -82,7 +82,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
std::shared_ptr<TStruct>
|
||||
UnlimitedHandleResource<THandle, TStruct, enumValue>::Get(THandle handle) {
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
|
||||
return nullptr;
|
||||
return m_structures[index];
|
||||
@@ -92,7 +92,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
std::shared_ptr<TStruct>
|
||||
UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(THandle handle) {
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
|
||||
return nullptr;
|
||||
return std::move(m_structures[index]);
|
||||
@@ -101,7 +101,7 @@ UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(THandle handle) {
|
||||
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
void UnlimitedHandleResource<THandle, TStruct, enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
for (size_t i = 0; i < m_structures.size(); i++) {
|
||||
m_structures[i].reset();
|
||||
}
|
||||
@@ -113,7 +113,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
template <typename Functor>
|
||||
void UnlimitedHandleResource<THandle, TStruct, enumValue>::ForEach(
|
||||
Functor func) {
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
size_t i;
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] != nullptr) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-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. */
|
||||
@@ -29,12 +29,12 @@ class SimCallbackRegistryBase {
|
||||
|
||||
public:
|
||||
void Cancel(int32_t uid) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
if (m_callbacks) m_callbacks->erase(uid - 1);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
DoReset();
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ template <typename CallbackFunction, const char* (*GetName)()>
|
||||
class SimCallbackRegistry : public impl::SimCallbackRegistryBase {
|
||||
public:
|
||||
int32_t Register(CallbackFunction callback, void* param) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
return DoRegister(reinterpret_cast<RawFunctor>(callback), param);
|
||||
}
|
||||
|
||||
template <typename... U>
|
||||
void Invoke(U&&... u) const {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
if (m_callbacks) {
|
||||
const char* name = GetName();
|
||||
for (auto&& cb : *m_callbacks)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-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. */
|
||||
@@ -27,14 +27,14 @@ class SimDataValueBase : protected SimCallbackRegistryBase {
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE void CancelCallback(int32_t uid) { Cancel(uid); }
|
||||
|
||||
T Get() const {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
return m_value;
|
||||
}
|
||||
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE operator T() const { return Get(); }
|
||||
|
||||
void Reset(T value) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
DoReset();
|
||||
m_value = value;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class SimDataValueBase : protected SimCallbackRegistryBase {
|
||||
protected:
|
||||
int32_t DoRegisterCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify, const char* name) {
|
||||
std::unique_lock<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
int32_t newUid = DoRegister(reinterpret_cast<RawFunctor>(callback), param);
|
||||
if (newUid == -1) return -1;
|
||||
if (initialNotify) {
|
||||
@@ -57,7 +57,7 @@ class SimDataValueBase : protected SimCallbackRegistryBase {
|
||||
}
|
||||
|
||||
void DoSet(T value, const char* name) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(this->m_mutex);
|
||||
std::lock_guard lock(this->m_mutex);
|
||||
if (m_value != value) {
|
||||
m_value = value;
|
||||
if (m_callbacks) {
|
||||
|
||||
Reference in New Issue
Block a user