Use wpi mutex and condition_variable. (#52)

This commit is contained in:
Peter Johnson
2017-11-12 22:12:03 -08:00
committed by GitHub
parent e45b6e0f65
commit 80618a2e64
4 changed files with 31 additions and 29 deletions

View File

@@ -9,10 +9,11 @@
#define WPIUTIL_SUPPORT_SAFETHREAD_H_
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
#include "support/condition_variable.h"
#include "support/mutex.h"
namespace wpi {
// Base class for SafeThreadOwner threads.
@@ -22,9 +23,9 @@ class SafeThread {
virtual ~SafeThread() = default;
virtual void Main() = 0;
std::mutex m_mutex;
wpi::mutex m_mutex;
std::atomic_bool m_active;
std::condition_variable m_cond;
wpi::condition_variable m_cond;
};
namespace detail {
@@ -42,11 +43,11 @@ class SafeThreadProxyBase {
}
}
explicit operator bool() const { return m_thread != nullptr; }
std::unique_lock<std::mutex>& GetLock() { return m_lock; }
std::unique_lock<wpi::mutex>& GetLock() { return m_lock; }
protected:
SafeThread* m_thread;
std::unique_lock<std::mutex> m_lock;
std::unique_lock<wpi::mutex> m_lock;
};
// A proxy for SafeThread.