34template <
typename THandle,
typename TStruct,
int16_t size,
50 std::shared_ptr<TStruct>
Get(THandle handle);
51 void Free(THandle handle);
55 std::array<std::shared_ptr<TStruct>,
size> m_structures;
56 std::array<wpi::mutex, size> m_handleMutexes;
59template <
typename THandle,
typename TStruct,
int16_t size,
65 if (index < 0 || index >=
size) {
69 std::scoped_lock lock(m_handleMutexes[
index]);
71 if (m_structures[
index] !=
nullptr) {
75 m_structures[
index] = toSet;
79template <
typename THandle,
typename TStruct,
int16_t size,
81std::shared_ptr<TStruct>
86 if (index < 0 || index >=
size) {
89 std::scoped_lock lock(m_handleMutexes[
index]);
92 return m_structures[
index];
95template <
typename THandle,
typename TStruct,
int16_t size,
101 if (index < 0 || index >=
size) {
105 std::scoped_lock lock(m_handleMutexes[
index]);
106 m_structures[
index].reset();
109template <
typename THandle,
typename TStruct,
int16_t size,
112 enumValue>::ResetHandles() {
113 for (
int i = 0; i <
size; i++) {
114 std::scoped_lock lock(m_handleMutexes[i]);
115 m_structures[i].reset();
Base for all HAL Handles.
Definition: HandlesInternal.h:28
virtual void ResetHandles()
int16_t m_version
Definition: HandlesInternal.h:38
The IndexedClassedHandleResource class is a way to track handles.
Definition: IndexedClassedHandleResource.h:36
std::shared_ptr< TStruct > Get(THandle handle)
Definition: IndexedClassedHandleResource.h:82
int16_t GetIndex(THandle handle)
Definition: IndexedClassedHandleResource.h:47
IndexedClassedHandleResource & operator=(const IndexedClassedHandleResource &)=delete
THandle Allocate(int16_t index, std::shared_ptr< TStruct > toSet, int32_t *status)
Definition: IndexedClassedHandleResource.h:62
friend class IndexedClassedHandleResourceTest
Definition: IndexedClassedHandleResource.h:37
void ResetHandles() override
Definition: IndexedClassedHandleResource.h:112
IndexedClassedHandleResource()=default
IndexedClassedHandleResource(const IndexedClassedHandleResource &)=delete
void Free(THandle handle)
Definition: IndexedClassedHandleResource.h:97
#define RESOURCE_OUT_OF_RANGE
Definition: Errors.h:80
#define RESOURCE_IS_ALLOCATED
Definition: Errors.h:78
#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