Cleaned up variable names for std::lock_guard and their associated mutexes (#759)

This commit is contained in:
Tyler Veness
2017-11-22 17:10:21 -08:00
committed by Peter Johnson
parent 96de0b5b11
commit ba879f4663
22 changed files with 136 additions and 137 deletions

View File

@@ -60,7 +60,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -78,7 +78,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -91,14 +91,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> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> 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> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -17,7 +17,6 @@
#include "HAL/Errors.h"
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/HandlesInternal.h"
namespace hal {
@@ -74,7 +73,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -94,7 +93,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -108,7 +107,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> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -117,7 +116,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> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -62,7 +62,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -81,7 +81,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -95,7 +95,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> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -103,7 +103,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> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -59,12 +59,12 @@ THandle
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
std::shared_ptr<TStruct> toSet) {
// globally lock to loop through indices
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> 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> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i] = toSet;
return static_cast<THandle>(createHandle(i, enumValue, m_version));
}
@@ -82,7 +82,7 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -96,8 +96,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> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -106,9 +106,9 @@ template <typename THandle, typename TStruct, int16_t size,
void LimitedClassedHandleResource<THandle, TStruct, size,
enumValue>::ResetHandles() {
{
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
for (int i = 0; i < size; i++) {
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
m_structures[i].reset();
}
}

View File

@@ -55,12 +55,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> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> 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> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i] = std::make_shared<TStruct>();
return static_cast<THandle>(createHandle(i, enumValue, m_version));
}
@@ -77,7 +77,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -91,8 +91,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> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -100,9 +100,9 @@ template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
void LimitedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
{
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
for (int i = 0; i < size; i++) {
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
m_structures[i].reset();
}
}

View File

@@ -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> sync(m_handleMutex);
std::lock_guard<wpi::mutex> 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> sync(m_handleMutex);
std::lock_guard<wpi::mutex> 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> sync(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
return nullptr;
return std::move(m_structures[index]);
@@ -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> sync(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] != nullptr) {