32template <
typename THandle,
typename TStruct, int16_t size,
43 THandle
Allocate(int16_t
index, std::shared_ptr<TStruct> toSet,
48 std::shared_ptr<TStruct>
Get(THandle handle);
49 void Free(THandle handle);
53 std::array<std::shared_ptr<TStruct>, size> m_structures;
54 std::array<wpi::util::mutex, size> m_handleMutexes;
57template <
typename THandle,
typename TStruct, int16_t size,
61 int16_t
index, std::shared_ptr<TStruct> toSet, int32_t* status) {
67 std::scoped_lock lock(m_handleMutexes[
index]);
69 if (m_structures[
index] !=
nullptr) {
73 m_structures[
index] = toSet;
74 return static_cast<THandle
>(
78template <
typename THandle,
typename TStruct, int16_t size,
80std::shared_ptr<TStruct>
88 std::scoped_lock lock(m_handleMutexes[
index]);
91 return m_structures[
index];
94template <
typename THandle,
typename TStruct, int16_t size,
104 std::scoped_lock lock(m_handleMutexes[
index]);
105 m_structures[
index].reset();
108template <
typename THandle,
typename TStruct, int16_t size,
112 for (
int i = 0; i < size; i++) {
113 std::scoped_lock lock(m_handleMutexes[i]);
114 m_structures[i].reset();
@ index
Definition base.h:690
virtual void ResetHandles()
int16_t m_version
Definition HandlesInternal.hpp:37
The IndexedClassedHandleResource class is a way to track handles.
Definition IndexedClassedHandleResource.hpp:34
std::shared_ptr< TStruct > Get(THandle handle)
Definition IndexedClassedHandleResource.hpp:81
THandle Allocate(int16_t index, std::shared_ptr< TStruct > toSet, int32_t *status)
Definition IndexedClassedHandleResource.hpp:60
friend class IndexedClassedHandleResourceTest
Definition IndexedClassedHandleResource.hpp:35
IndexedClassedHandleResource & operator=(const IndexedClassedHandleResource &)=delete
int16_t GetIndex(THandle handle)
Definition IndexedClassedHandleResource.hpp:45
IndexedClassedHandleResource(const IndexedClassedHandleResource &)=delete
void ResetHandles() override
Definition IndexedClassedHandleResource.hpp:111
void Free(THandle handle)
Definition IndexedClassedHandleResource.hpp:96
IndexedClassedHandleResource()=default
#define RESOURCE_OUT_OF_RANGE
Definition Errors.h:84
#define RESOURCE_IS_ALLOCATED
Definition Errors.h:82
#define HAL_kInvalidHandle
Definition Types.h:15
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition Types.hpp:9
HAL_HandleEnum
Enum of HAL handle types.
Definition HandlesInternal.hpp:45
int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType, int16_t version)
Get if the handle is a correct type and version.
Definition HandlesInternal.hpp:135
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType, int16_t version)
Create a handle for a specific index, type and version.