From 067b1f3ee0900b5fa4d63ca610cbf9eb357ab67f Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 9 May 2017 22:04:57 -0700 Subject: [PATCH] Adds a way to get the native handle from SafeThread (#198) Useful to wpilib to enable easier changing of RT priorities. --- include/support/SafeThread.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/support/SafeThread.h b/include/support/SafeThread.h index 465957be3d..0f39bc6811 100644 --- a/include/support/SafeThread.h +++ b/include/support/SafeThread.h @@ -82,9 +82,13 @@ class SafeThreadOwnerBase { protected: void Start(SafeThread* thr); SafeThread* GetThread() const { return m_thread.load(); } + std::thread::native_handle_type GetNativeThreadHandle() const { + return m_nativeHandle; + } private: std::atomic m_thread; + std::atomic m_nativeHandle; }; inline void SafeThreadOwnerBase::Start(SafeThread* thr) { @@ -94,10 +98,12 @@ inline void SafeThreadOwnerBase::Start(SafeThread* thr) { delete newthr; return; } - std::thread([=]() { + std::thread stdThread([=]() { newthr->Main(); delete newthr; - }).detach(); + }); + m_nativeHandle = stdThread.native_handle(); + stdThread.detach(); } inline void SafeThreadOwnerBase::Stop() {