| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Multi-threaded tests of ConditionVariable class. | 5 // Multi-threaded tests of ConditionVariable class. |
| 6 | 6 |
| 7 #include <time.h> | 7 #include <time.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" | |
| 16 #include "base/synchronization/condition_variable.h" | 14 #include "base/synchronization/condition_variable.h" |
| 17 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 18 #include "base/synchronization/spin_wait.h" | 16 #include "base/synchronization/spin_wait.h" |
| 19 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 20 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 21 #include "base/threading/thread_collision_warner.h" | 19 #include "base/threading/thread_collision_warner.h" |
| 22 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 25 | 23 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 PLOG(ERROR) << "Could not set time of day. Run as root?"; | 213 PLOG(ERROR) << "Could not set time of day. Run as root?"; |
| 216 return; | 214 return; |
| 217 } | 215 } |
| 218 | 216 |
| 219 Lock lock; | 217 Lock lock; |
| 220 ConditionVariable cv(&lock); | 218 ConditionVariable cv(&lock); |
| 221 lock.Acquire(); | 219 lock.Acquire(); |
| 222 | 220 |
| 223 Thread thread("Helper"); | 221 Thread thread("Helper"); |
| 224 thread.Start(); | 222 thread.Start(); |
| 225 thread.task_runner()->PostTask(FROM_HERE, base::Bind(&BackInTime, &lock)); | 223 thread.message_loop()->PostTask(FROM_HERE, base::Bind(&BackInTime, &lock)); |
| 226 | 224 |
| 227 TimeTicks start = TimeTicks::Now(); | 225 TimeTicks start = TimeTicks::Now(); |
| 228 const TimeDelta kWaitTime = TimeDelta::FromMilliseconds(300); | 226 const TimeDelta kWaitTime = TimeDelta::FromMilliseconds(300); |
| 229 // Allow for clocking rate granularity. | 227 // Allow for clocking rate granularity. |
| 230 const TimeDelta kFudgeTime = TimeDelta::FromMilliseconds(50); | 228 const TimeDelta kFudgeTime = TimeDelta::FromMilliseconds(50); |
| 231 | 229 |
| 232 cv.TimedWait(kWaitTime + kFudgeTime); | 230 cv.TimedWait(kWaitTime + kFudgeTime); |
| 233 TimeDelta duration = TimeTicks::Now() - start; | 231 TimeDelta duration = TimeTicks::Now() - start; |
| 234 | 232 |
| 235 thread.Stop(); | 233 thread.Stop(); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 base::AutoLock auto_lock(lock_); | 754 base::AutoLock auto_lock(lock_); |
| 757 // Send notification that we completed our "work." | 755 // Send notification that we completed our "work." |
| 758 WorkIsCompleted(thread_id); | 756 WorkIsCompleted(thread_id); |
| 759 } | 757 } |
| 760 } | 758 } |
| 761 } | 759 } |
| 762 | 760 |
| 763 } // namespace | 761 } // namespace |
| 764 | 762 |
| 765 } // namespace base | 763 } // namespace base |
| OLD | NEW |