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

Commit

Permalink
SafeThread: Use atomic for m_active.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Nov 5, 2016
1 parent 05ca76e commit 34acd9d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions wpiutil/include/support/SafeThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ namespace wpi {
// Base class for SafeThreadOwner threads.
class SafeThread {
public:
SafeThread() { m_active = true; }
virtual ~SafeThread() = default;
virtual void Main() = 0;

std::mutex m_mutex;
bool m_active = true;
std::atomic_bool m_active;
std::condition_variable m_cond;
};

Expand Down Expand Up @@ -92,7 +93,6 @@ inline void SafeThreadOwnerBase::Start(SafeThread* thr) {
inline void SafeThreadOwnerBase::Stop() {
SafeThread* thr = m_thread.exchange(nullptr);
if (!thr) return;
std::lock_guard<std::mutex> lock(thr->m_mutex);
thr->m_active = false;
thr->m_cond.notify_one();
}
Expand Down

0 comments on commit 34acd9d

Please sign in to comment.