WPILibC++ 2023.4.3-108-ge5452e3
wpi::java::JCallbackThread< T > Class Template Reference

Generic callback thread implementation. More...

#include <wpi/jni_util.h>

Inheritance diagram for wpi::java::JCallbackThread< T >:
wpi::SafeThread wpi::SafeThreadBase

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
 

Detailed Description

template<typename T>
class wpi::java::JCallbackThread< T >

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);

Member Function Documentation

◆ Main()

template<typename T >
void wpi::java::JCallbackThread< T >::Main
overridevirtual

Implements wpi::SafeThreadBase.

Member Data Documentation

◆ m_func

template<typename T >
jobject wpi::java::JCallbackThread< T >::m_func = nullptr

◆ m_mid

template<typename T >
jmethodID wpi::java::JCallbackThread< T >::m_mid

◆ m_queue

template<typename T >
std::queue<T> wpi::java::JCallbackThread< T >::m_queue

The documentation for this class was generated from the following file: