Adds a way to get the native handle from SafeThread (#198)

Useful to wpilib to enable easier changing of RT priorities.
This commit is contained in:
Thad House
2017-05-09 22:04:57 -07:00
committed by Peter Johnson
parent 9a2ec13ba4
commit 067b1f3ee0

View File

@@ -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) {
@@ -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() {