32template <
typename THandle,
typename TStruct,
int16_t size>
51 std::array<std::shared_ptr<TStruct>,
size> m_structures;
52 std::array<wpi::mutex, size> m_handleMutexes;
55template <
typename THandle,
typename TStruct,
int16_t size>
56std::shared_ptr<TStruct>
60 if (index < 0 || index >=
size) {
65 std::scoped_lock lock(m_handleMutexes[
index]);
67 if (m_structures[
index] !=
nullptr) {
70 return m_structures[
index];
72 m_structures[
index] = std::make_shared<TStruct>();
76 return m_structures[
index];
79template <
typename THandle,
typename TStruct,
int16_t size>
84 if (index < 0 || index >=
size) {
87 std::scoped_lock lock(m_handleMutexes[
index]);
90 return m_structures[
index];
93template <
typename THandle,
typename TStruct,
int16_t size>
98 if (index < 0 || index >=
size) {
102 std::scoped_lock lock(m_handleMutexes[
index]);
103 m_structures[
index].reset();
106template <
typename THandle,
typename TStruct,
int16_t size>
108 for (
int i = 0; i <
size; i++) {
109 std::scoped_lock lock(m_handleMutexes[i]);
110 m_structures[i].reset();
The DigitalHandleResource class is a way to track handles.
Definition: DigitalHandleResource.h:33
DigitalHandleResource(const DigitalHandleResource &)=delete
friend class DigitalHandleResourceTest
Definition: DigitalHandleResource.h:34
std::shared_ptr< TStruct > Get(THandle handle, HAL_HandleEnum enumValue)
Definition: DigitalHandleResource.h:80
DigitalHandleResource()=default
int16_t GetIndex(THandle handle, HAL_HandleEnum enumValue)
Definition: DigitalHandleResource.h:43
std::shared_ptr< TStruct > Allocate(int16_t index, HAL_HandleEnum enumValue, THandle *handle, int32_t *status)
Definition: DigitalHandleResource.h:57
void ResetHandles() override
Definition: DigitalHandleResource.h:107
void Free(THandle handle, HAL_HandleEnum enumValue)
Definition: DigitalHandleResource.h:94
DigitalHandleResource & operator=(const DigitalHandleResource &)=delete
Base for all HAL Handles.
Definition: HandlesInternal.h:28
virtual void ResetHandles()
int16_t m_version
Definition: HandlesInternal.h:38
#define RESOURCE_OUT_OF_RANGE
Definition: Errors.h:80
#define RESOURCE_IS_ALLOCATED
Definition: Errors.h:78
#define HAL_SUCCESS
Definition: Errors.h:44
#define HAL_kInvalidHandle
Definition: Types.h:15
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
::int16_t int16_t
Definition: Meta.h:55
::int32_t int32_t
Definition: Meta.h:57
GHC_FS_API file_status status(const path &p, std::error_code &ec) noexcept
Definition: filesystem.hpp:4892
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: ChipObject.h:40
HAL_HandleEnum
Enum of HAL handle types.
Definition: HandlesInternal.h:46
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType, int16_t version)
Create a handle for a specific index, type and version.
int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType, int16_t version)
Get if the handle is a correct type and version.
Definition: HandlesInternal.h:134