From d20e89ae768c6a7581be2ae828f28c5889e81f90 Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 15 Feb 2016 14:12:23 -0800 Subject: [PATCH 1/2] Adds threaded callbacks Change-Id: I051a1c62645ef9e6571b38f8e0a87d27eda141d9 --- hal/include/HAL/CallbackThread.hpp | 46 +++++++ hal/include/HAL/Interrupts.hpp | 3 + hal/include/HAL/Notifier.hpp | 2 + .../cpp/lib => hal/include}/SafeThread.h | 0 hal/lib/Athena/CallbackThread.cpp | 66 ++++++++++ hal/lib/Athena/Interrupts.cpp | 17 +++ hal/lib/Athena/Notifier.cpp | 29 +++++ .../cpp/lib => hal/lib/Shared}/SafeThread.cpp | 0 .../Athena/src/InterruptableSensorBase.cpp | 2 +- wpilibc/Athena/src/Notifier.cpp | 2 +- wpilibj/src/athena/cpp/lib/InterruptJNI.cpp | 116 ++++++------------ wpilibj/src/athena/cpp/lib/NotifierJNI.cpp | 115 ++++++----------- 12 files changed, 240 insertions(+), 158 deletions(-) create mode 100644 hal/include/HAL/CallbackThread.hpp rename {wpilibj/src/athena/cpp/lib => hal/include}/SafeThread.h (100%) create mode 100644 hal/lib/Athena/CallbackThread.cpp rename {wpilibj/src/athena/cpp/lib => hal/lib/Shared}/SafeThread.cpp (100%) diff --git a/hal/include/HAL/CallbackThread.hpp b/hal/include/HAL/CallbackThread.hpp new file mode 100644 index 00000000..a23c2427 --- /dev/null +++ b/hal/include/HAL/CallbackThread.hpp @@ -0,0 +1,46 @@ +#include "SafeThread.h" + +// Thread where callbacks are actually performed. +// +// In C++, this allows notifiers to run long. With the standard notifier +// if you had a notifier callback that took 1 second to run, no other +// notifiers would run until that callback completed. This allows it to +// run in a seperate thread, which make notifiers non blocking. +// +// For Java, JNI's AttachCurrentThread() creates a Java Thread object on every +// invocation, which is both time inefficient and causes issues with Eclipse +// (which tries to keep a thread list up-to-date and thus gets swamped). +// Instead, this class attaches just once. When a hardware notification +// occurs, a condition variable wakes up this thread and this thread actually +// makes the callback. +// +// We don't want to use a FIFO here. If the user code takes too long to +// process, we will just ignore the redundant wakeup. +class CallbackThreadHAL : public SafeThread { + public: + void Main(); + + bool m_notify = false; + void* m_param = nullptr; + int32_t (*m_init)(void*) = nullptr; + void (*m_process)(uint64_t, void*) = nullptr; + void (*m_end)(void*) = nullptr; + uint64_t m_mask; +}; + +class CallbackThread : public SafeThreadOwner { + public: + void SetFunc(int32_t (*init)(void*), void (*process)(uint64_t, void*), + void (*end)(void*), void* param); + void* GetParam(); + + void Notify(uint64_t mask) { + auto thr = GetThread(); + if (!thr) return; + thr->m_mask = mask; + thr->m_notify = true; + thr->m_cond.notify_one(); + } +}; + +void callbackHandler(uint64_t mask, void* param); \ No newline at end of file diff --git a/hal/include/HAL/Interrupts.hpp b/hal/include/HAL/Interrupts.hpp index a41ca6be..15d21d66 100644 --- a/hal/include/HAL/Interrupts.hpp +++ b/hal/include/HAL/Interrupts.hpp @@ -21,6 +21,9 @@ extern "C" bool routing_analog_trigger, int32_t *status); void attachInterruptHandler(void* interrupt_pointer, InterruptHandlerFunction handler, void* param, int32_t *status); + void attachInterruptHandlerThreaded(void* interrupt_pointer, int32_t (*init)(void*), + void (*process)(uint64_t, void*), void (*end)(void*), + void* param, int32_t *status); void setInterruptUpSourceEdge(void* interrupt_pointer, bool risingEdge, bool fallingEdge, int32_t *status); } diff --git a/hal/include/HAL/Notifier.hpp b/hal/include/HAL/Notifier.hpp index e8cb3812..902cca1c 100644 --- a/hal/include/HAL/Notifier.hpp +++ b/hal/include/HAL/Notifier.hpp @@ -6,6 +6,8 @@ extern "C" { void* initializeNotifier(void (*process)(uint64_t, void*), void* param, int32_t *status); void cleanNotifier(void* notifier_pointer, int32_t *status); + void* initializeNotifierThreaded(int32_t (*init)(void*), void (*process)(uint64_t, void*), void (*end)(void*), void *param, int32_t *status); + void* cleanNotifierThreaded(void* notifier_pointer, int32_t *status); void* getNotifierParam(void* notifier_pointer, int32_t *status); void updateNotifierAlarm(void* notifier_pointer, uint64_t triggerTime, int32_t *status); void stopNotifierAlarm(void* notifier_pointer, int32_t *status); diff --git a/wpilibj/src/athena/cpp/lib/SafeThread.h b/hal/include/SafeThread.h similarity index 100% rename from wpilibj/src/athena/cpp/lib/SafeThread.h rename to hal/include/SafeThread.h diff --git a/hal/lib/Athena/CallbackThread.cpp b/hal/lib/Athena/CallbackThread.cpp new file mode 100644 index 00000000..8e133598 --- /dev/null +++ b/hal/lib/Athena/CallbackThread.cpp @@ -0,0 +1,66 @@ +#include "HAL/CallbackThread.hpp" +#include +#include +#include + +void CallbackThread::SetFunc(int32_t (*init)(void*), void (*process)(uint64_t, void*), + void (*end)(void*), void* param) { + auto thr = GetThread(); + if (!thr) return; + thr->m_param = param; + thr->m_init = init; + thr->m_process = process; + thr->m_end = end; + thr->m_notify = true; + thr->m_cond.notify_one(); +} + +void* CallbackThread::GetParam() { + auto thr = GetThread(); + if (!thr) return nullptr; + return thr->m_param; +} + +void CallbackThreadHAL::Main() { + { + std::unique_lock lock(m_mutex); + m_cond.wait(lock, [&] { return !m_active || m_notify; }); + if (!m_active) return; + if (m_init) + { + auto init = m_init; + auto param = m_param; + lock.unlock(); // don't hold mutex during init execution + int32_t rv = init(param); + lock.lock(); + if (rv != 0) return; + } + } + + std::unique_lock lock(m_mutex); + while (m_active) { + m_cond.wait(lock, [&] { return !m_active || m_notify; }); + if (!m_active) break; + m_notify = false; + if (!m_process) continue; + auto process = m_process; + auto param = m_param; + uint64_t mask = m_mask; + lock.unlock(); // don't hold mutex during callback execution + process(mask, param); + lock.lock(); + } + + if (m_end) + { + auto end = m_end; + auto param = m_param; + lock.unlock(); // don't hold mutex during end execution + end(param); + lock.lock(); + } +} + +void callbackHandler(uint64_t mask, void* param) { + ((CallbackThread*)param)->Notify(mask); +} \ No newline at end of file diff --git a/hal/lib/Athena/Interrupts.cpp b/hal/lib/Athena/Interrupts.cpp index 55c4660f..d5cf32ec 100644 --- a/hal/lib/Athena/Interrupts.cpp +++ b/hal/lib/Athena/Interrupts.cpp @@ -6,6 +6,7 @@ /*----------------------------------------------------------------------------*/ #include "HAL/Interrupts.hpp" +#include "HAL/CallbackThread.hpp" #include "ChipObject.h" extern void remapDigitalSource(bool analogTrigger, uint32_t &pin, uint8_t &module); @@ -123,6 +124,22 @@ void attachInterruptHandler(void* interrupt_pointer, InterruptHandlerFunction ha anInterrupt->manager->registerHandler(handler, param, status); } +void interruptHandler(uint32_t mask, void* param) +{ + callbackHandler(mask, param); +} + +void attachInterruptHandlerThreaded(void* interrupt_pointer, int32_t (*init)(void*), + void (*process)(uint64_t, void*), void (*end)(void*), + void* param, int32_t *status) +{ + CallbackThread* thr = new CallbackThread; + thr->Start(); + thr->SetFunc(init, process, end, param); + + attachInterruptHandler(interrupt_pointer, interruptHandler, thr, status); +} + void setInterruptUpSourceEdge(void* interrupt_pointer, bool risingEdge, bool fallingEdge, int32_t *status) { diff --git a/hal/lib/Athena/Notifier.cpp b/hal/lib/Athena/Notifier.cpp index 2184b5ae..46a859f3 100644 --- a/hal/lib/Athena/Notifier.cpp +++ b/hal/lib/Athena/Notifier.cpp @@ -6,12 +6,14 @@ /*----------------------------------------------------------------------------*/ #include "HAL/Notifier.hpp" +#include "HAL/CallbackThread.hpp" #include "ChipObject.h" #include "HAL/HAL.hpp" #include "HAL/cpp/priority_mutex.h" #include #include #include +#include "SafeThread.h" static const uint32_t kTimerInterruptNumber = 28; @@ -99,6 +101,33 @@ void* initializeNotifier(void (*process)(uint64_t, void*), void *param, int32_t return notifier; } +void* initializeNotifierThreaded(int32_t (*init)(void*), void (*process)(uint64_t, void*), void (*end)(void*), void *param, int32_t *status) +{ + CallbackThread* notify = new CallbackThread; + notify->Start(); + notify->SetFunc(init, process, end, param); + + void *notifierPtr = initializeNotifier(callbackHandler, notify, status); + + if (!notifierPtr || *status != 0) + { + delete notify; + } + + return notifierPtr; +} + +void* cleanNotifierThreaded(void* notifier_pointer, int32_t *status) +{ + CallbackThread* notify = (CallbackThread*)getNotifierParam(notifier_pointer, status); + void* param = nullptr; + if (notify) + param = notify->GetParam(); + cleanNotifier(notifier_pointer, status); + delete notify; + return param; +} + void cleanNotifier(void* notifier_pointer, int32_t *status) { { diff --git a/wpilibj/src/athena/cpp/lib/SafeThread.cpp b/hal/lib/Shared/SafeThread.cpp similarity index 100% rename from wpilibj/src/athena/cpp/lib/SafeThread.cpp rename to hal/lib/Shared/SafeThread.cpp diff --git a/wpilibc/Athena/src/InterruptableSensorBase.cpp b/wpilibc/Athena/src/InterruptableSensorBase.cpp index 7c9a80f4..d4d3b5a0 100644 --- a/wpilibc/Athena/src/InterruptableSensorBase.cpp +++ b/wpilibc/Athena/src/InterruptableSensorBase.cpp @@ -41,7 +41,7 @@ void InterruptableSensorBase::RequestInterrupts( requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(), GetAnalogTriggerForRouting(), &status); SetUpSourceEdge(true, false); - attachInterruptHandler(m_interrupt, handler, param, &status); + attachInterruptHandlerThreaded(m_interrupt, nullptr, handler, nullptr, param, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); } diff --git a/wpilibc/Athena/src/Notifier.cpp b/wpilibc/Athena/src/Notifier.cpp index 0023100d..614939e0 100644 --- a/wpilibc/Athena/src/Notifier.cpp +++ b/wpilibc/Athena/src/Notifier.cpp @@ -21,7 +21,7 @@ Notifier::Notifier(TimerEventHandler handler) { wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr"); m_handler = handler; int32_t status = 0; - m_notifier = initializeNotifier(&Notifier::Notify, this, &status); + m_notifier = initializeNotifierThreaded(nullptr, &Notifier::Notify, nullptr, this, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); } diff --git a/wpilibj/src/athena/cpp/lib/InterruptJNI.cpp b/wpilibj/src/athena/cpp/lib/InterruptJNI.cpp index 14257993..d127fab5 100644 --- a/wpilibj/src/athena/cpp/lib/InterruptJNI.cpp +++ b/wpilibj/src/athena/cpp/lib/InterruptJNI.cpp @@ -24,92 +24,46 @@ TLogLevel interruptJNILogLevel = logERROR; if (level > interruptJNILogLevel) ; \ else Log().Get(level) -// Thread where callbacks are actually performed. -// -// JNI's AttachCurrentThread() creates a Java Thread object on every -// invocation, which is both time inefficient and causes issues with Eclipse -// (which tries to keep a thread list up-to-date and thus gets swamped). -// -// Instead, this class attaches just once. When a hardware notification -// occurs, a condition variable wakes up this thread and this thread actually -// makes the call into Java. -// -// We don't want to use a FIFO here. If the user code takes too long to -// process, we will just ignore the redundant wakeup. -class InterruptThreadJNI : public SafeThread { - public: - void Main(); - - bool m_notify = false; - uint32_t m_mask = 0; - jobject m_func = nullptr; - jmethodID m_mid; - jobject m_param = nullptr; -}; - -class InterruptJNI : public SafeThreadOwner { - public: - void SetFunc(JNIEnv* env, jobject func, jmethodID mid, jobject param); - - void Notify(uint32_t mask) { - auto thr = GetThread(); - if (!thr) return; - thr->m_notify = true; - thr->m_mask = mask; - thr->m_cond.notify_one(); - } +struct InterruptData { + JNIEnv *env; + jobject func = nullptr; + jmethodID mid; + jobject param = nullptr; }; -void InterruptJNI::SetFunc(JNIEnv* env, jobject func, jmethodID mid, - jobject param) { - auto thr = GetThread(); - if (!thr) return; - // free global references - if (thr->m_func) env->DeleteGlobalRef(thr->m_func); - if (thr->m_param) env->DeleteGlobalRef(thr->m_param); - // create global references - thr->m_func = env->NewGlobalRef(func); - thr->m_param = param ? env->NewGlobalRef(param) : nullptr; - thr->m_mid = mid; -} - -void InterruptThreadJNI::Main() { +static int32_t interruptInit(void* param) { + if (!param) return 1; + InterruptData* data = (InterruptData*)param; JNIEnv *env; JavaVMAttachArgs args; args.version = JNI_VERSION_1_2; args.name = const_cast("Interrupt"); args.group = nullptr; jint rs = jvm->AttachCurrentThreadAsDaemon((void**)&env, &args); - if (rs != JNI_OK) return; - - std::unique_lock lock(m_mutex); - while (m_active) { - m_cond.wait(lock, [&] { return !m_active || m_notify; }); - if (!m_active) break; - m_notify = false; - if (!m_func) continue; - jobject func = m_func; - jmethodID mid = m_mid; - uint32_t mask = m_mask; - jobject param = m_param; - lock.unlock(); // don't hold mutex during callback execution - env->CallVoidMethod(func, mid, (jint)mask, param); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - env->ExceptionClear(); - } - lock.lock(); - } - - // free global references - if (m_func) env->DeleteGlobalRef(m_func); - if (m_param) env->DeleteGlobalRef(m_param); + if (rs != JNI_OK) return 1; + data->env = env; + return 0; +} - jvm->DetachCurrentThread(); +static void interruptProcess(uint64_t mask, void* param) { + if (!param) return; + InterruptData* data = (InterruptData*)param; + if (!data->func) return; + JNIEnv* env = data->env; + env->CallVoidMethod(data->func, data->mid, (jint)mask, data->param); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } } -void interruptHandler(uint32_t mask, void* param) { - ((InterruptJNI*)param)->Notify(mask); +static void interruptEnd(void* param) { + if (param) { + InterruptData* data = (InterruptData*)param; + if (data->func) data->env->DeleteGlobalRef(data->func); + if (data->param) data->env->DeleteGlobalRef(data->param); + } + jvm->DetachCurrentThread(); } extern "C" { @@ -301,14 +255,16 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterru return; } - InterruptJNI* intr = new InterruptJNI; - intr->Start(); - intr->SetFunc(env, handler, mid, param); + InterruptData* intr = new InterruptData; + intr->func = env->NewGlobalRef(handler); + intr->param = param ? env->NewGlobalRef(param) : nullptr; + intr->mid = mid; INTERRUPTJNI_LOG(logDEBUG) << "InterruptThreadJNI Ptr = " << intr; - + int32_t status = 0; - attachInterruptHandler((void*)interrupt_pointer, interruptHandler, intr, + attachInterruptHandlerThreaded((void*)interrupt_pointer, interruptInit, interruptProcess, + interruptEnd, intr, &status); INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; diff --git a/wpilibj/src/athena/cpp/lib/NotifierJNI.cpp b/wpilibj/src/athena/cpp/lib/NotifierJNI.cpp index 92245477..6d2e6208 100644 --- a/wpilibj/src/athena/cpp/lib/NotifierJNI.cpp +++ b/wpilibj/src/athena/cpp/lib/NotifierJNI.cpp @@ -26,88 +26,47 @@ TLogLevel notifierJNILogLevel = logWARNING; if (level > notifierJNILogLevel) ; \ else Log().Get(level) -// Thread where callbacks are actually performed. -// -// JNI's AttachCurrentThread() creates a Java Thread object on every -// invocation, which is both time inefficient and causes issues with Eclipse -// (which tries to keep a thread list up-to-date and thus gets swamped). -// -// Instead, this class attaches just once. When a hardware notification -// occurs, a condition variable wakes up this thread and this thread actually -// makes the call into Java. -// -// We don't want to use a FIFO here. If the user code takes too long to -// process, we will just ignore the redundant wakeup. -class NotifierThreadJNI : public SafeThread { - public: - void Main(); - - bool m_notify = false; - jobject m_func = nullptr; - jmethodID m_mid; - uint64_t m_currentTime; -}; - -class NotifierJNI : public SafeThreadOwner { - public: - void SetFunc(JNIEnv* env, jobject func, jmethodID mid); - - void Notify(uint64_t currentTime) { - auto thr = GetThread(); - if (!thr) return; - thr->m_currentTime = currentTime; - thr->m_notify = true; - thr->m_cond.notify_one(); - } +struct NotifierData { + JNIEnv *env; + jobject func = nullptr; + jmethodID mid; }; -void NotifierJNI::SetFunc(JNIEnv* env, jobject func, jmethodID mid) { - auto thr = GetThread(); - if (!thr) return; - // free global reference - if (thr->m_func) env->DeleteGlobalRef(thr->m_func); - // create global reference - thr->m_func = env->NewGlobalRef(func); - thr->m_mid = mid; -} - -void NotifierThreadJNI::Main() { +static int32_t notifierInit(void* param) { + if (!param) return 1; + NotifierData* data = (NotifierData*)param; JNIEnv *env; JavaVMAttachArgs args; args.version = JNI_VERSION_1_2; args.name = const_cast("Notifier"); args.group = nullptr; jint rs = jvm->AttachCurrentThreadAsDaemon((void**)&env, &args); - if (rs != JNI_OK) return; - - std::unique_lock lock(m_mutex); - while (m_active) { - m_cond.wait(lock, [&] { return !m_active || m_notify; }); - if (!m_active) break; - m_notify = false; - if (!m_func) continue; - jobject func = m_func; - jmethodID mid = m_mid; - uint64_t currentTime = m_currentTime; - lock.unlock(); // don't hold mutex during callback execution - env->CallVoidMethod(func, mid, (jlong)currentTime); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - env->ExceptionClear(); - } - lock.lock(); + if (rs != JNI_OK) return 1; + data->env = env; + return 0; +} + +static void notifierProcess(uint64_t currentTimeInt, void* param) { + if (!param) return; + NotifierData* data = (NotifierData*)param; + if (!data->func) return; + JNIEnv* env = data->env; + env->CallVoidMethod(data->func, data->mid, (jlong)currentTimeInt); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); } +} - // free global reference - if (m_func) env->DeleteGlobalRef(m_func); +static void notifierEnd(void* param) { + if (param) { + NotifierData* data = (NotifierData*)param; + if (data->func) data->env->DeleteGlobalRef(data->func); + } jvm->DetachCurrentThread(); } -void notifierHandler(uint64_t currentTimeInt, void* param) { - ((NotifierJNI*)param)->Notify(currentTimeInt); -} - extern "C" { /* @@ -135,11 +94,11 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNot // each notifier runs in its own thread; this is so if one takes too long // to execute, it doesn't keep the others from running - NotifierJNI* notify = new NotifierJNI; - notify->Start(); - notify->SetFunc(env, func, mid); + NotifierData* notify = new NotifierData; + notify->func = env->NewGlobalRef(func); + notify->mid = mid; int32_t status = 0; - void *notifierPtr = initializeNotifier(notifierHandler, notify, &status); + void *notifierPtr = initializeNotifierThreaded(notifierInit, notifierProcess, notifierEnd, notify, &status); NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << notifierPtr; NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status; @@ -163,14 +122,18 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_cleanNotifier NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI cleanNotifier"; NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void *)notifierPtr; + + int32_t status = 0; - NotifierJNI* notify = - (NotifierJNI*)getNotifierParam((void*)notifierPtr, &status); - cleanNotifier((void*)notifierPtr, &status); + //NotifierJNI* notify = + //(NotifierJNI*)getNotifierParam((void*)notifierPtr, &status); + void* d = cleanNotifierThreaded((void*)notifierPtr, &status); NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status; CheckStatus(env, status); - delete notify; + if (!d) return; + NotifierData* data = (NotifierData*)d; + delete data; } /* From f37caa6bc67ee4756570f4bcb4b9dcb392916bcb Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 3 Apr 2016 22:36:25 -0700 Subject: [PATCH 2/2] Attempting to fix Java Interrupt Threaded callback. Most likely will be forced to be 2 separate classes each for interrupt and notifier Change-Id: If88fda53ede64eb3ab5360ed6037d590b83c7de4 --- hal/include/HAL/Interrupts.hpp | 2 +- hal/lib/Athena/Interrupts.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hal/include/HAL/Interrupts.hpp b/hal/include/HAL/Interrupts.hpp index 15d21d66..2eb8bbbb 100644 --- a/hal/include/HAL/Interrupts.hpp +++ b/hal/include/HAL/Interrupts.hpp @@ -22,7 +22,7 @@ extern "C" void attachInterruptHandler(void* interrupt_pointer, InterruptHandlerFunction handler, void* param, int32_t *status); void attachInterruptHandlerThreaded(void* interrupt_pointer, int32_t (*init)(void*), - void (*process)(uint64_t, void*), void (*end)(void*), + InterruptHandlerFunction handler, void (*end)(void*), void* param, int32_t *status); void setInterruptUpSourceEdge(void* interrupt_pointer, bool risingEdge, bool fallingEdge, int32_t *status); diff --git a/hal/lib/Athena/Interrupts.cpp b/hal/lib/Athena/Interrupts.cpp index d5cf32ec..1d2b14bc 100644 --- a/hal/lib/Athena/Interrupts.cpp +++ b/hal/lib/Athena/Interrupts.cpp @@ -130,12 +130,15 @@ void interruptHandler(uint32_t mask, void* param) } void attachInterruptHandlerThreaded(void* interrupt_pointer, int32_t (*init)(void*), - void (*process)(uint64_t, void*), void (*end)(void*), + InterruptHandlerFunction handler, void (*end)(void*), void* param, int32_t *status) { CallbackThread* thr = new CallbackThread; thr->Start(); - thr->SetFunc(init, process, end, param); + + thr->SetFunc(init, [handler](uint64_t m, void* p) -> void { + handler((uint32_t) m, p); + }, end, param); attachInterruptHandler(interrupt_pointer, interruptHandler, thr, status); }