mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
wpiutil: SafeThread: Add thread id, support getting shared_ptr (#1722)
Rename base class function from GetThread to GetThreadSharedPtr.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -32,6 +32,7 @@ void detail::SafeThreadOwnerBase::Start(std::shared_ptr<SafeThread> thr) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (auto thr = m_thread.lock()) return;
|
||||
m_stdThread = std::thread([=] { thr->Main(); });
|
||||
thr->m_threadId = m_stdThread.get_id();
|
||||
m_thread = thr;
|
||||
}
|
||||
|
||||
@@ -80,7 +81,8 @@ detail::SafeThreadOwnerBase::GetNativeThreadHandle() {
|
||||
return m_stdThread.native_handle();
|
||||
}
|
||||
|
||||
std::shared_ptr<SafeThread> detail::SafeThreadOwnerBase::GetThread() const {
|
||||
std::shared_ptr<SafeThread> detail::SafeThreadOwnerBase::GetThreadSharedPtr()
|
||||
const {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_thread.lock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user