OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/threading/platform_thread.h" | 5 #include "base/threading/platform_thread.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 // Tests of basic thread functions --------------------------------------------- | 53 // Tests of basic thread functions --------------------------------------------- |
54 | 54 |
55 class FunctionTestThread : public TrivialThread { | 55 class FunctionTestThread : public TrivialThread { |
56 public: | 56 public: |
57 FunctionTestThread() : thread_id_(0) {} | 57 FunctionTestThread() : thread_id_(0) {} |
58 | 58 |
59 virtual void ThreadMain() { | 59 virtual void ThreadMain() { |
60 thread_id_ = PlatformThread::CurrentId(); | 60 thread_id_ = PlatformThread::CurrentId(); |
61 PlatformThread::YieldCurrentThread(); | 61 PlatformThread::YieldCurrentThread(); |
62 PlatformThread::Sleep(50); | 62 PlatformThread::Sleep(TimeDelta::FromMilliseconds(50)); |
63 | 63 |
64 TrivialThread::ThreadMain(); | 64 TrivialThread::ThreadMain(); |
65 } | 65 } |
66 | 66 |
67 PlatformThreadId thread_id() const { return thread_id_; } | 67 PlatformThreadId thread_id() const { return thread_id_; } |
68 | 68 |
69 private: | 69 private: |
70 PlatformThreadId thread_id_; | 70 PlatformThreadId thread_id_; |
71 | 71 |
72 DISALLOW_COPY_AND_ASSIGN(FunctionTestThread); | 72 DISALLOW_COPY_AND_ASSIGN(FunctionTestThread); |
(...skipping 24 matching lines...) Expand all Loading... |
97 ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); | 97 ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n])); |
98 for (size_t n = 0; n < arraysize(thread); n++) | 98 for (size_t n = 0; n < arraysize(thread); n++) |
99 PlatformThread::Join(handle[n]); | 99 PlatformThread::Join(handle[n]); |
100 for (size_t n = 0; n < arraysize(thread); n++) { | 100 for (size_t n = 0; n < arraysize(thread); n++) { |
101 ASSERT_TRUE(thread[n].did_run()); | 101 ASSERT_TRUE(thread[n].did_run()); |
102 EXPECT_NE(thread[n].thread_id(), main_thread_id); | 102 EXPECT_NE(thread[n].thread_id(), main_thread_id); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 } // namespace base | 106 } // namespace base |
OLD | NEW |