35template <
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::util::mutex, size> m_handleMutexes;
59template <
typename THandle,
typename TStruct, int16_t size,
63 int16_t
index, std::string_view
name,
int offset) {
68 size + offset,
index + offset));
70 std::scoped_lock lock(m_handleMutexes[
index]);
72 if (m_structures[
index] !=
nullptr) {
76 m_structures[
index]->previousAllocation));
82 m_structures[
index] = std::make_shared<TStruct>();
85 return std::pair{handle, m_structures[
index]};
88template <
typename THandle,
typename TStruct, int16_t size,
90std::shared_ptr<TStruct>
97 std::scoped_lock lock(m_handleMutexes[
index]);
100 return m_structures[
index];
103template <
typename THandle,
typename TStruct, int16_t size,
113 std::scoped_lock lock(m_handleMutexes[
index]);
114 m_structures[
index].reset();
117template <
typename THandle,
typename TStruct, int16_t size,
120 for (
int i = 0; i < size; i++) {
121 std::scoped_lock lock(m_handleMutexes[i]);
122 m_structures[i].reset();
@ index
Definition base.h:690
@ name
Definition base.h:690
virtual void ResetHandles()
int16_t m_version
Definition HandlesInternal.hpp:47
void ResetHandles() override
Definition IndexedHandleResource.hpp:119
IndexedHandleResource()=default
int16_t GetIndex(THandle handle)
Definition IndexedHandleResource.hpp:47
friend class IndexedHandleResourceTest
Definition IndexedHandleResource.hpp:38
wpi::util::expected< std::pair< THandle, std::shared_ptr< TStruct > >, HAL_Status > Allocate(int16_t index, std::string_view name, int offset=0)
Definition IndexedHandleResource.hpp:62
void Free(THandle handle)
Definition IndexedHandleResource.hpp:105
std::shared_ptr< TStruct > Get(THandle handle)
Definition IndexedHandleResource.hpp:91
IndexedHandleResource & operator=(const IndexedHandleResource &)=delete
IndexedHandleResource(const IndexedHandleResource &)=delete
An expected<T, E> object is an object that contains the storage for another object and manages the li...
Definition expected:1250
Definition HandlesInternal.hpp:29
#define HAL_RESOURCE_IS_ALLOCATED
Definition Errors.h:39
#define HAL_RESOURCE_OUT_OF_RANGE
Definition Errors.h:41
int32_t HAL_Status
Definition Types.h:67
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition Types.hpp:9
HAL_HandleEnum
Enum of HAL handle types.
Definition HandlesInternal.hpp:55
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:139
HAL_Status MakeErrorIndexOutOfRange(HAL_Status status, std::string_view message, int32_t minimum, int32_t maximum, int32_t channel)
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType, int16_t version)
Create a handle for a specific index, type and version.
HAL_Status MakeErrorPreviouslyAllocated(HAL_Status status, std::string_view message, int32_t channel, std::string_view previousAllocation)