34template <
typename THandle,
typename TStruct, int16_t size,
46 int16_t
index, std::shared_ptr<TStruct> toSet, std::string_view
name,
51 std::shared_ptr<TStruct>
Get(THandle handle);
52 void Free(THandle handle);
56 std::array<std::shared_ptr<TStruct>, size> m_structures;
57 std::array<wpi::util::mutex, size> m_handleMutexes;
60template <
typename THandle,
typename TStruct, int16_t size,
64 int16_t
index, std::shared_ptr<TStruct> toSet, std::string_view
name,
70 size + offset,
index + offset));
72 std::scoped_lock lock(m_handleMutexes[
index]);
74 if (m_structures[
index] !=
nullptr) {
78 m_structures[
index]->previousAllocation));
84 m_structures[
index] = toSet;
85 return static_cast<THandle
>(
89template <
typename THandle,
typename TStruct, int16_t size,
91std::shared_ptr<TStruct>
99 std::scoped_lock lock(m_handleMutexes[
index]);
102 return m_structures[
index];
105template <
typename THandle,
typename TStruct, int16_t size,
115 std::scoped_lock lock(m_handleMutexes[
index]);
116 m_structures[
index].reset();
119template <
typename THandle,
typename TStruct, int16_t size,
123 for (
int i = 0; i < size; i++) {
124 std::scoped_lock lock(m_handleMutexes[i]);
125 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
The IndexedClassedHandleResource class is a way to track handles.
Definition IndexedClassedHandleResource.hpp:36
wpi::util::expected< THandle, HAL_Status > Allocate(int16_t index, std::shared_ptr< TStruct > toSet, std::string_view name, int offset=0)
Definition IndexedClassedHandleResource.hpp:63
std::shared_ptr< TStruct > Get(THandle handle)
Definition IndexedClassedHandleResource.hpp:92
friend class IndexedClassedHandleResourceTest
Definition IndexedClassedHandleResource.hpp:37
IndexedClassedHandleResource & operator=(const IndexedClassedHandleResource &)=delete
int16_t GetIndex(THandle handle)
Definition IndexedClassedHandleResource.hpp:48
IndexedClassedHandleResource(const IndexedClassedHandleResource &)=delete
void ResetHandles() override
Definition IndexedClassedHandleResource.hpp:122
void Free(THandle handle)
Definition IndexedClassedHandleResource.hpp:107
IndexedClassedHandleResource()=default
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
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)