Use ThreadChecker in debug only.

This commit is contained in:
Alex Zolotarev 2015-06-01 21:41:59 +03:00
parent 1e55db8051
commit ab0a54023f
3 changed files with 12 additions and 10 deletions

View file

@ -48,19 +48,19 @@ DeferredTask::DeferredTask(TTask const & task, milliseconds ms) : m_started(fals
DeferredTask::~DeferredTask()
{
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
m_thread.Cancel();
}
bool DeferredTask::WasStarted() const
{
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
return m_started;
}
void DeferredTask::Cancel()
{
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
threads::IRoutine * routine = m_thread.GetRoutine();
CHECK(routine, ());
routine->Cancel();
@ -68,6 +68,6 @@ void DeferredTask::Cancel()
void DeferredTask::WaitForCompletion()
{
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
m_thread.Join();
}

View file

@ -53,7 +53,9 @@ private:
/// is used by routine that will be executed on m_thread.
atomic<bool> m_started;
threads::Thread m_thread;
#ifdef DEBUG
ThreadChecker m_threadChecker;
#endif
DISALLOW_COPY_AND_MOVE(DeferredTask);
};

View file

@ -24,7 +24,7 @@ public:
}
~WorkerThread() {
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
if (IsRunning())
RunUntilIdleAndStop();
CHECK(!IsRunning(), ());
@ -36,7 +36,7 @@ public:
/// \param task A callable object that will be called by worker thread.
void Push(shared_ptr<Task> task)
{
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
CHECK(IsRunning(), ());
unique_lock<mutex> lock(m_mutex);
m_condNotFull.wait(lock, [this]()
@ -51,7 +51,7 @@ public:
/// terminates worker thread.
void RunUntilIdleAndStop()
{
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
CHECK(IsRunning(), ());
{
lock_guard<mutex> lock(m_mutex);
@ -63,7 +63,7 @@ public:
/// \return True if worker thread is running, false otherwise.
inline bool IsRunning() const {
CHECK(m_threadChecker.CalledOnOriginalThread(), ());
ASSERT(m_threadChecker.CalledOnOriginalThread(), ());
return m_workerThread.joinable();
}
@ -101,9 +101,9 @@ private:
condition_variable m_condNotFull;
condition_variable m_condNonEmpty;
thread m_workerThread;
#ifdef DEBUG
ThreadChecker m_threadChecker;
#endif
DISALLOW_COPY_AND_MOVE(WorkerThread);
}; // class WorkerThread
} // namespace my