Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Adds a way to get the native handle from SafeThread (#198)
Browse files Browse the repository at this point in the history
Useful to wpilib to enable easier changing of RT priorities.
  • Loading branch information
ThadHouse authored and PeterJohnson committed May 10, 2017
1 parent 42facbb commit 3d2f41d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions wpiutil/include/support/SafeThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SafeThread*> m_thread;
std::atomic<std::thread::native_handle_type> m_nativeHandle;
};

inline void SafeThreadOwnerBase::Start(SafeThread* thr) {
Expand All @@ -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() {
Expand Down

0 comments on commit 3d2f41d

Please sign in to comment.