WPILibC++ 2023.4.3-108-ge5452e3
|
Generic callback thread implementation. More...
#include <wpi/jni_util.h>
Public Member Functions | |
void | Main () override |
Public Member Functions inherited from wpi::SafeThread | |
void | Stop () override |
Public Member Functions inherited from wpi::SafeThreadBase | |
virtual | ~SafeThreadBase ()=default |
virtual void | Main ()=0 |
virtual void | Stop ()=0 |
Public Attributes | |
std::queue< T > | m_queue |
jobject | m_func = nullptr |
jmethodID | m_mid |
Public Attributes inherited from wpi::SafeThread | |
wpi::condition_variable | m_cond |
Public Attributes inherited from wpi::SafeThreadBase | |
wpi::mutex | m_mutex |
std::atomic_bool | m_active {true} |
std::thread::id | m_threadId |
Generic callback thread implementation.
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.
The template parameter T is the message being passed to the callback, but also needs to provide the following functions: static JavaVM* GetJVM(); static const char* GetName(); void CallJava(JNIEnv *env, jobject func, jmethodID mid);
|
overridevirtual |
Implements wpi::SafeThreadBase.
jobject wpi::java::JCallbackThread< T >::m_func = nullptr |
jmethodID wpi::java::JCallbackThread< T >::m_mid |
std::queue<T> wpi::java::JCallbackThread< T >::m_queue |