| 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 #include "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/threading/platform_thread.h" | 6 #include "base/threading/platform_thread.h" |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| 11 | 11 |
| 12 // Trivial tests that thread runs and doesn't crash on create and join --------- | 12 // Trivial tests that thread runs and doesn't crash on create and join --------- |
| 13 | 13 |
| 14 class TrivialThread : public PlatformThread::Delegate { | 14 class TrivialThread : public PlatformThread::Delegate { |
| 15 public: | 15 public: |
| 16 TrivialThread() : did_run_(false) {} | 16 TrivialThread() : did_run_(false) {} |
| 17 | 17 |
| 18 virtual void ThreadMain() OVERRIDE { | 18 virtual void ThreadMain() override { |
| 19 did_run_ = true; | 19 did_run_ = true; |
| 20 } | 20 } |
| 21 | 21 |
| 22 bool did_run() const { return did_run_; } | 22 bool did_run() const { return did_run_; } |
| 23 | 23 |
| 24 private: | 24 private: |
| 25 bool did_run_; | 25 bool did_run_; |
| 26 | 26 |
| 27 DISALLOW_COPY_AND_ASSIGN(TrivialThread); | 27 DISALLOW_COPY_AND_ASSIGN(TrivialThread); |
| 28 }; | 28 }; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 for (size_t n = 0; n < arraysize(thread); n++) | 50 for (size_t n = 0; n < arraysize(thread); n++) |
| 51 ASSERT_TRUE(thread[n].did_run()); | 51 ASSERT_TRUE(thread[n].did_run()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Tests of basic thread functions --------------------------------------------- | 54 // Tests of basic thread functions --------------------------------------------- |
| 55 | 55 |
| 56 class FunctionTestThread : public TrivialThread { | 56 class FunctionTestThread : public TrivialThread { |
| 57 public: | 57 public: |
| 58 FunctionTestThread() : thread_id_(0) {} | 58 FunctionTestThread() : thread_id_(0) {} |
| 59 | 59 |
| 60 virtual void ThreadMain() OVERRIDE { | 60 virtual void ThreadMain() override { |
| 61 thread_id_ = PlatformThread::CurrentId(); | 61 thread_id_ = PlatformThread::CurrentId(); |
| 62 PlatformThread::YieldCurrentThread(); | 62 PlatformThread::YieldCurrentThread(); |
| 63 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50)); | 63 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50)); |
| 64 | 64 |
| 65 // Make sure that the thread ID is the same across calls. | 65 // Make sure that the thread ID is the same across calls. |
| 66 EXPECT_EQ(thread_id_, PlatformThread::CurrentId()); | 66 EXPECT_EQ(thread_id_, PlatformThread::CurrentId()); |
| 67 | 67 |
| 68 TrivialThread::ThreadMain(); | 68 TrivialThread::ThreadMain(); |
| 69 } | 69 } |
| 70 | 70 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 for (size_t i = 0; i < n; ++i) { | 112 for (size_t i = 0; i < n; ++i) { |
| 113 EXPECT_NE(thread[i].thread_id(), thread[n].thread_id()); | 113 EXPECT_NE(thread[i].thread_id(), thread[n].thread_id()); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Make sure that the thread ID is the same across calls. | 117 // Make sure that the thread ID is the same across calls. |
| 118 EXPECT_EQ(main_thread_id, PlatformThread::CurrentId()); | 118 EXPECT_EQ(main_thread_id, PlatformThread::CurrentId()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace base | 121 } // namespace base |
| OLD | NEW |