From ab0a54023f2895f211bfc10ded87abaf72198268 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 1 Jun 2015 21:41:59 +0300 Subject: [PATCH] Use ThreadChecker in debug only. --- base/deferred_task.cpp | 8 ++++---- base/deferred_task.hpp | 2 ++ base/worker_thread.hpp | 12 ++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/base/deferred_task.cpp b/base/deferred_task.cpp index fdc396dfbd..4760187518 100644 --- a/base/deferred_task.cpp +++ b/base/deferred_task.cpp @@ -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(); } diff --git a/base/deferred_task.hpp b/base/deferred_task.hpp index ecbc3b4c45..8255104a2e 100644 --- a/base/deferred_task.hpp +++ b/base/deferred_task.hpp @@ -53,7 +53,9 @@ private: /// is used by routine that will be executed on m_thread. atomic m_started; threads::Thread m_thread; +#ifdef DEBUG ThreadChecker m_threadChecker; +#endif DISALLOW_COPY_AND_MOVE(DeferredTask); }; diff --git a/base/worker_thread.hpp b/base/worker_thread.hpp index 4943e96da9..f6ec72944d 100644 --- a/base/worker_thread.hpp +++ b/base/worker_thread.hpp @@ -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) { - CHECK(m_threadChecker.CalledOnOriginalThread(), ()); + ASSERT(m_threadChecker.CalledOnOriginalThread(), ()); CHECK(IsRunning(), ()); unique_lock 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 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