WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::util::java::JCallbackThread< T > Class Template Reference

Generic callback thread implementation. More...

#include <wpi/util/jni_util.hpp>

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

Public Member Functions

void Main () override
Public Member Functions inherited from wpi::util::SafeThread
void Stop () override
Public Member Functions inherited from wpi::util::SafeThreadBase
virtual ~SafeThreadBase ()=default

Public Attributes

std::queue< T > m_queue
jobject m_func = nullptr
jmethodID m_mid
Public Attributes inherited from wpi::util::SafeThread
wpi::util::condition_variable m_cond
Public Attributes inherited from wpi::util::SafeThreadBase
wpi::util::mutex m_mutex
std::atomic_bool m_active {true}
std::thread::id m_threadId

Detailed Description

template<typename T>
class wpi::util::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::util::java::JCallbackThread< T >::Main ( )
overridevirtual

Member Data Documentation

◆ m_func

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

◆ m_mid

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

◆ m_queue

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

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