31template <
typename THandle,
typename TStruct, int16_t size,
41 std::shared_ptr<TStruct>
Allocate(int16_t
index, THandle* handle,
46 std::shared_ptr<TStruct>
Get(THandle handle);
47 void Free(THandle handle);
51 std::array<std::shared_ptr<TStruct>, size> m_structures;
52 std::array<wpi::util::mutex, size> m_handleMutexes;
55template <
typename THandle,
typename TStruct, int16_t size,
57std::shared_ptr<TStruct>
59 int16_t
index, THandle* handle, int32_t* status) {
66 std::scoped_lock lock(m_handleMutexes[
index]);
68 if (m_structures[
index] !=
nullptr) {
71 return m_structures[
index];
73 m_structures[
index] = std::make_shared<TStruct>();
77 return m_structures[
index];
80template <
typename THandle,
typename TStruct, int16_t size,
82std::shared_ptr<TStruct>
89 std::scoped_lock lock(m_handleMutexes[
index]);
92 return m_structures[
index];
95template <
typename THandle,
typename TStruct, int16_t size,
105 std::scoped_lock lock(m_handleMutexes[
index]);
106 m_structures[
index].reset();
109template <
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
void ResetHandles() override
Definition IndexedHandleResource.hpp:111
IndexedHandleResource()=default
int16_t GetIndex(THandle handle)
Definition IndexedHandleResource.hpp:43
friend class IndexedHandleResourceTest
Definition IndexedHandleResource.hpp:34
void Free(THandle handle)
Definition IndexedHandleResource.hpp:97
std::shared_ptr< TStruct > Get(THandle handle)
Definition IndexedHandleResource.hpp:83
IndexedHandleResource & operator=(const IndexedHandleResource &)=delete
std::shared_ptr< TStruct > Allocate(int16_t index, THandle *handle, int32_t *status)
Definition IndexedHandleResource.hpp:58
IndexedHandleResource(const IndexedHandleResource &)=delete
#define RESOURCE_OUT_OF_RANGE
Definition Errors.h:84
#define RESOURCE_IS_ALLOCATED
Definition Errors.h:82
#define HAL_SUCCESS
Definition Errors.h:48
#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.