From 36000ddb36599c571e643f6637690ed00e60ae01 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 23 Sep 2018 16:15:54 -0700 Subject: [PATCH] wpiutil: uv::Loop: Store the thread ID of the loop --- wpiutil/src/main/native/include/wpi/uv/Loop.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wpiutil/src/main/native/include/wpi/uv/Loop.h b/wpiutil/src/main/native/include/wpi/uv/Loop.h index 727e43247e..2b3b27fb71 100644 --- a/wpiutil/src/main/native/include/wpi/uv/Loop.h +++ b/wpiutil/src/main/native/include/wpi/uv/Loop.h @@ -10,9 +10,11 @@ #include +#include #include #include #include +#include #include #include "wpi/Signal.h" @@ -95,8 +97,10 @@ class Loop final : public std::enable_shared_from_this { * @return True when done, false in all other cases. */ bool Run(Mode mode = kDefault) { - return uv_run(m_loop, static_cast(static_cast(mode))) == - 0; + m_tid = std::this_thread::get_id(); + int rv = uv_run(m_loop, static_cast(static_cast(mode))); + m_tid = std::thread::id{}; + return rv == 0; } /** @@ -223,6 +227,12 @@ class Loop final : public std::enable_shared_from_this { */ void SetData(std::shared_ptr data) { m_data = std::move(data); } + /** + * Get the thread id of the loop thread. If the loop is not currently + * running, returns default-constructed thread id. + */ + std::thread::id GetThreadId() const { return m_tid; } + /** * Error signal */ @@ -238,6 +248,7 @@ class Loop final : public std::enable_shared_from_this { std::shared_ptr m_data; uv_loop_t* m_loop; uv_loop_t m_loopStruct; + std::atomic m_tid; }; } // namespace uv