diff --git a/wpiutil/src/main/native/cpp/EventLoopRunner.cpp b/wpiutil/src/main/native/cpp/EventLoopRunner.cpp index 2061e96681..5d90d531d0 100644 --- a/wpiutil/src/main/native/cpp/EventLoopRunner.cpp +++ b/wpiutil/src/main/native/cpp/EventLoopRunner.cpp @@ -63,3 +63,8 @@ void EventLoopRunner::ExecSync(LoopFunc func) { } } } + +std::shared_ptr EventLoopRunner::GetLoop() { + if (auto thr = m_owner.GetThread()) return thr->m_loop; + return nullptr; +} diff --git a/wpiutil/src/main/native/include/wpi/EventLoopRunner.h b/wpiutil/src/main/native/include/wpi/EventLoopRunner.h index 1e643ba7ff..71c0f681c7 100644 --- a/wpiutil/src/main/native/include/wpi/EventLoopRunner.h +++ b/wpiutil/src/main/native/include/wpi/EventLoopRunner.h @@ -9,6 +9,7 @@ #define WPIUTIL_WPI_EVENTLOOPRUNNER_H_ #include +#include #include "wpi/SafeThread.h" #include "wpi/uv/Loop.h" @@ -42,6 +43,12 @@ class EventLoopRunner { */ void ExecSync(LoopFunc func); + /** + * Get the loop. If the loop thread is not running, returns nullptr. + * @return The loop + */ + std::shared_ptr GetLoop(); + private: class Thread; SafeThreadOwner m_owner;