mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11: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:
@@ -27,6 +27,7 @@ class SafeThread {
|
||||
mutable wpi::mutex m_mutex;
|
||||
std::atomic_bool m_active{true};
|
||||
wpi::condition_variable m_cond;
|
||||
std::thread::id m_threadId;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@@ -83,7 +84,7 @@ class SafeThreadOwnerBase {
|
||||
|
||||
protected:
|
||||
void Start(std::shared_ptr<SafeThread> thr);
|
||||
std::shared_ptr<SafeThread> GetThread() const;
|
||||
std::shared_ptr<SafeThread> GetThreadSharedPtr() const;
|
||||
|
||||
private:
|
||||
mutable wpi::mutex m_mutex;
|
||||
@@ -107,7 +108,12 @@ class SafeThreadOwner : public detail::SafeThreadOwnerBase {
|
||||
|
||||
using Proxy = typename detail::SafeThreadProxy<T>;
|
||||
Proxy GetThread() const {
|
||||
return Proxy(detail::SafeThreadOwnerBase::GetThread());
|
||||
return Proxy(detail::SafeThreadOwnerBase::GetThreadSharedPtr());
|
||||
}
|
||||
|
||||
std::shared_ptr<T> GetThreadSharedPtr() const {
|
||||
return std::static_pointer_cast<T>(
|
||||
detail::SafeThreadOwnerBase::GetThreadSharedPtr());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user