45 if (callback ==
nullptr) {
51 return m_callbacks->emplace_back(param, callback) + 1;
72template <
typename CallbackFunction, const
char* (*GetName)()>
75 int32_t
Register(CallbackFunction callback,
void* param) {
80 template <
typename... U>
83 std::scoped_lock<wpi::recursive_spinlock> lock(
m_mutex);
88 const char* name = GetName();
90 reinterpret_cast<CallbackFunction
>(cb.callback)(name, cb.param,
91 std::forward<U>(u)...);
96 template <
typename... U>
98 return Invoke(std::forward<U>(u)...);
107#define HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(NAME) \
108 static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr const char* \
109 Get##NAME##Name() { \
127#define HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI(TYPE, NS, CAPINAME, DATA, \
129 int32_t NS##_Register##CAPINAME##Callback(int32_t index, TYPE callback, \
131 return DATA[index].LOWERNAME.Register(callback, param); \
134 void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) { \
135 DATA[index].LOWERNAME.Cancel(uid); \
151#define HAL_SIMCALLBACKREGISTRY_DEFINE_CAPI_NOINDEX(TYPE, NS, CAPINAME, DATA, \
153 int32_t NS##_Register##CAPINAME##Callback(TYPE callback, void* param) { \
154 return DATA->LOWERNAME.Register(callback, param); \
157 void NS##_Cancel##CAPINAME##Callback(int32_t uid) { \
158 DATA->LOWERNAME.Cancel(uid); \
173#define HAL_SIMCALLBACKREGISTRY_STUB_CAPI(TYPE, NS, CAPINAME) \
174 int32_t NS##_Register##CAPINAME##Callback(int32_t index, TYPE callback, \
179 void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) {}
192#define HAL_SIMCALLBACKREGISTRY_STUB_CAPI_NOINDEX(TYPE, NS, CAPINAME) \
193 int32_t NS##_Register##CAPINAME##Callback(TYPE callback, void* param) { \
197 void NS##_Cancel##CAPINAME##Callback(int32_t uid) {}
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
Definition: Compiler.h:258
Simulation callback registry.
Definition: SimCallbackRegistry.h:73
void Invoke(U &&... u) const
Definition: SimCallbackRegistry.h:81
LLVM_ATTRIBUTE_ALWAYS_INLINE void operator()(U &&... u) const
Definition: SimCallbackRegistry.h:97
int32_t Register(CallbackFunction callback, void *param)
Definition: SimCallbackRegistry.h:75
Definition: SimCallbackRegistry.h:20
void Cancel(int32_t uid)
Definition: SimCallbackRegistry.h:28
wpi::recursive_spinlock & GetMutex()
Definition: SimCallbackRegistry.h:40
LLVM_ATTRIBUTE_ALWAYS_INLINE void DoReset()
Definition: SimCallbackRegistry.h:54
wpi::recursive_spinlock m_mutex
Definition: SimCallbackRegistry.h:60
void(*)() RawFunctor
Definition: SimCallbackRegistry.h:22
int32_t DoRegister(RawFunctor callback, void *param)
Definition: SimCallbackRegistry.h:43
void Reset()
Definition: SimCallbackRegistry.h:35
std::unique_ptr< CallbackVector > m_callbacks
Definition: SimCallbackRegistry.h:61
Vector which provides an integrated freelist for removal and reuse of individual elements.
Definition: UidVector.h:73
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: ChipObject.h:40
recursive_spinlock1 recursive_spinlock
Definition: spinlock.h:141