diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-17 02:25:44 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-17 02:25:44 +0000 |
commit | 2d4537d50684e97458ca6d27e98e742533bb1141 (patch) | |
tree | 90141a594a60c4f55e512cacbe5ca736f7ee2354 /base/condition_variable_unittest.cc | |
parent | 3b680a8b28f63a13f82fbb5e7324fba69c28d75d (diff) | |
download | chromium_src-2d4537d50684e97458ca6d27e98e742533bb1141.zip chromium_src-2d4537d50684e97458ca6d27e98e742533bb1141.tar.gz chromium_src-2d4537d50684e97458ca6d27e98e742533bb1141.tar.bz2 |
Adds a helper class used to mark/define critical section in a class and then install controls to check that those critical sections are not violated.
This CL is due the thread posted on chromium-dev:
http://groups.google.com/group/chromium-dev/browse_frm/thread/30af0b63b6adb245.
From Gaetano Mendola <mendola bigfoot com>
Review URL: http://codereview.chromium.org/8621
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7127 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/condition_variable_unittest.cc')
-rw-r--r-- | base/condition_variable_unittest.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/base/condition_variable_unittest.cc b/base/condition_variable_unittest.cc index c996f2c..8ca4bc1 100644 --- a/base/condition_variable_unittest.cc +++ b/base/condition_variable_unittest.cc @@ -13,6 +13,7 @@ #include "base/platform_thread.h" #include "base/scoped_ptr.h" #include "base/spin_wait.h" +#include "base/thread_collision_warner.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -79,6 +80,9 @@ class WorkQueue : public PlatformThread::Delegate { int shutdown_task_count() const; void thread_shutting_down(); + + //---------------------------------------------------------------------------- + // Worker threads can call them but not needed to acquire a lock Lock* lock(); ConditionVariable* work_is_available(); @@ -120,6 +124,8 @@ class WorkQueue : public PlatformThread::Delegate { TimeDelta worker_delay_; // Time each task takes to complete. bool allow_help_requests_; // Workers can signal more workers. bool shutdown_; // Set when threads need to terminate. + + DFAKE_MUTEX(locked_methods_); }; //------------------------------------------------------------------------------ @@ -477,15 +483,18 @@ WorkQueue::~WorkQueue() { } int WorkQueue::GetThreadId() { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); DCHECK(!EveryIdWasAllocated()); return thread_started_counter_++; // Give out Unique IDs. } bool WorkQueue::EveryIdWasAllocated() const { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); return thread_count_ == thread_started_counter_; } TimeDelta WorkQueue::GetAnAssignment(int thread_id) { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); DCHECK_LT(0, task_count_); assignment_history_[thread_id]++; if (0 == --task_count_) { @@ -495,26 +504,32 @@ TimeDelta WorkQueue::GetAnAssignment(int thread_id) { } void WorkQueue::WorkIsCompleted(int thread_id) { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); completion_history_[thread_id]++; } int WorkQueue::task_count() const { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); return task_count_; } bool WorkQueue::allow_help_requests() const { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); return allow_help_requests_; } bool WorkQueue::shutdown() const { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); return shutdown_; } int WorkQueue::shutdown_task_count() const { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); return shutdown_task_count_; } void WorkQueue::thread_shutting_down() { + DFAKE_SCOPED_RECURSIVE_LOCK(locked_methods_); shutdown_task_count_++; } |