OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 29 matching lines...) Expand all Loading... |
41 int msec_; | 41 int msec_; |
42 }; | 42 }; |
43 | 43 |
44 class SleepInsideInitThread : public Thread { | 44 class SleepInsideInitThread : public Thread { |
45 public: | 45 public: |
46 SleepInsideInitThread() : Thread("none") { | 46 SleepInsideInitThread() : Thread("none") { |
47 init_called_ = false; | 47 init_called_ = false; |
48 ANNOTATE_BENIGN_RACE( | 48 ANNOTATE_BENIGN_RACE( |
49 this, "Benign test-only data race on vptr - http://crbug.com/98219"); | 49 this, "Benign test-only data race on vptr - http://crbug.com/98219"); |
50 } | 50 } |
51 virtual ~SleepInsideInitThread() { } | 51 virtual ~SleepInsideInitThread() { |
| 52 Stop(); |
| 53 } |
52 | 54 |
53 virtual void Init() { | 55 virtual void Init() { |
54 base::PlatformThread::Sleep(500); | 56 base::PlatformThread::Sleep(500); |
55 init_called_ = true; | 57 init_called_ = true; |
56 } | 58 } |
57 bool InitCalled() { return init_called_; } | 59 bool InitCalled() { return init_called_; } |
58 private: | 60 private: |
59 bool init_called_; | 61 bool init_called_; |
60 }; | 62 }; |
61 | 63 |
(...skipping 16 matching lines...) Expand all Loading... |
78 class CaptureToEventList : public Thread { | 80 class CaptureToEventList : public Thread { |
79 public: | 81 public: |
80 // This Thread pushes events into the vector |event_list| to show | 82 // This Thread pushes events into the vector |event_list| to show |
81 // the order they occured in. |event_list| must remain valid for the | 83 // the order they occured in. |event_list| must remain valid for the |
82 // lifetime of this thread. | 84 // lifetime of this thread. |
83 explicit CaptureToEventList(EventList* event_list) | 85 explicit CaptureToEventList(EventList* event_list) |
84 : Thread("none"), event_list_(event_list) { | 86 : Thread("none"), event_list_(event_list) { |
85 } | 87 } |
86 | 88 |
87 virtual ~CaptureToEventList() { | 89 virtual ~CaptureToEventList() { |
88 // Must call Stop() manually to have our CleanUp() function called. | |
89 Stop(); | 90 Stop(); |
90 } | 91 } |
91 | 92 |
92 virtual void Init() { | 93 virtual void Init() { |
93 event_list_->push_back(THREAD_EVENT_INIT); | 94 event_list_->push_back(THREAD_EVENT_INIT); |
94 } | 95 } |
95 | 96 |
96 virtual void CleanUp() { | 97 virtual void CleanUp() { |
97 event_list_->push_back(THREAD_EVENT_CLEANUP); | 98 event_list_->push_back(THREAD_EVENT_CLEANUP); |
98 } | 99 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 250 |
250 // Upon leaving this scope, the thread is deleted. | 251 // Upon leaving this scope, the thread is deleted. |
251 } | 252 } |
252 | 253 |
253 // Check the order of events during shutdown. | 254 // Check the order of events during shutdown. |
254 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); | 255 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); |
255 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); | 256 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); |
256 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); | 257 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); |
257 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); | 258 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); |
258 } | 259 } |
OLD | NEW |