| 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/threading/thread.h" | 5 #include "base/threading/thread.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 EXPECT_EQ("ThreadName", a.thread_name()); | 207 EXPECT_EQ("ThreadName", a.thread_name()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(ThreadTest, ThreadId) { | 210 TEST_F(ThreadTest, ThreadId) { |
| 211 Thread a("ThreadId0"); | 211 Thread a("ThreadId0"); |
| 212 Thread b("ThreadId1"); | 212 Thread b("ThreadId1"); |
| 213 a.Start(); | 213 a.Start(); |
| 214 b.Start(); | 214 b.Start(); |
| 215 | 215 |
| 216 // Post a task that calls GetThreadId() on the created thread. | 216 // Post a task that calls GetThreadId() on the created thread. |
| 217 base::WaitableEvent event(false, false); | 217 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 218 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 218 base::PlatformThreadId id_from_new_thread; | 219 base::PlatformThreadId id_from_new_thread; |
| 219 a.task_runner()->PostTask( | 220 a.task_runner()->PostTask( |
| 220 FROM_HERE, base::Bind(ReturnThreadId, &a, &id_from_new_thread, &event)); | 221 FROM_HERE, base::Bind(ReturnThreadId, &a, &id_from_new_thread, &event)); |
| 221 | 222 |
| 222 // Call GetThreadId() on the current thread before calling event.Wait() so | 223 // Call GetThreadId() on the current thread before calling event.Wait() so |
| 223 // that this test can find a race issue with TSAN. | 224 // that this test can find a race issue with TSAN. |
| 224 base::PlatformThreadId id_from_current_thread = a.GetThreadId(); | 225 base::PlatformThreadId id_from_current_thread = a.GetThreadId(); |
| 225 | 226 |
| 226 // Check if GetThreadId() returns consistent value in both threads. | 227 // Check if GetThreadId() returns consistent value in both threads. |
| 227 event.Wait(); | 228 event.Wait(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 EXPECT_FALSE(a.task_runner()); | 295 EXPECT_FALSE(a.task_runner()); |
| 295 } | 296 } |
| 296 | 297 |
| 297 TEST_F(ThreadTest, MultipleWaitUntilThreadStarted) { | 298 TEST_F(ThreadTest, MultipleWaitUntilThreadStarted) { |
| 298 Thread a("MultipleWaitUntilThreadStarted"); | 299 Thread a("MultipleWaitUntilThreadStarted"); |
| 299 EXPECT_TRUE(a.Start()); | 300 EXPECT_TRUE(a.Start()); |
| 300 // It's OK to call WaitUntilThreadStarted() multiple times. | 301 // It's OK to call WaitUntilThreadStarted() multiple times. |
| 301 EXPECT_TRUE(a.WaitUntilThreadStarted()); | 302 EXPECT_TRUE(a.WaitUntilThreadStarted()); |
| 302 EXPECT_TRUE(a.WaitUntilThreadStarted()); | 303 EXPECT_TRUE(a.WaitUntilThreadStarted()); |
| 303 } | 304 } |
| OLD | NEW |