From de6d6c9a5cb76177c8a5b1af67530e0987992056 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 23 Sep 2018 16:14:56 -0700 Subject: [PATCH] wpiutil: EventLoopRunner: Allow getting the loop shared_ptr. --- wpiutil/src/main/native/cpp/EventLoopRunner.cpp | 5 +++++ wpiutil/src/main/native/include/wpi/EventLoopRunner.h | 7 +++++++ 2 files changed, 12 insertions(+) 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;