Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: base/test/test_io_thread.cc

Issue 2170953002: Fix MemoryDumpManagerTest's thread unsafe usage of the base::TestIOThread API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a0_a_0_thread_cleanup
Patch Set: Keep re-enabling base::Thread::Stop() checks for follow-up CL. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/test/test_io_thread.h ('k') | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/test/test_io_thread.h" 5 #include "base/test/test_io_thread.h"
6 6
7 #include "base/bind.h" 7 #include "base/logging.h"
8 #include "base/callback.h"
9 #include "base/synchronization/waitable_event.h"
10
11 namespace {
12
13 void PostTaskAndWaitHelper(base::WaitableEvent* event,
14 const base::Closure& task) {
15 task.Run();
16 event->Signal();
17 }
18
19 } // namespace
20 8
21 namespace base { 9 namespace base {
22 10
23 TestIOThread::TestIOThread(Mode mode) 11 TestIOThread::TestIOThread(Mode mode)
24 : io_thread_("test_io_thread"), io_thread_started_(false) { 12 : io_thread_("test_io_thread"), io_thread_started_(false) {
25 switch (mode) { 13 switch (mode) {
26 case kAutoStart: 14 case kAutoStart:
27 Start(); 15 Start();
28 return; 16 return;
29 case kManualStart: 17 case kManualStart:
(...skipping 17 matching lines...) Expand all
47 // Note: It's okay to call |Stop()| even if the thread isn't running. 35 // Note: It's okay to call |Stop()| even if the thread isn't running.
48 io_thread_.Stop(); 36 io_thread_.Stop();
49 io_thread_started_ = false; 37 io_thread_started_ = false;
50 } 38 }
51 39
52 void TestIOThread::PostTask(const tracked_objects::Location& from_here, 40 void TestIOThread::PostTask(const tracked_objects::Location& from_here,
53 const base::Closure& task) { 41 const base::Closure& task) {
54 task_runner()->PostTask(from_here, task); 42 task_runner()->PostTask(from_here, task);
55 } 43 }
56 44
57 void TestIOThread::PostTaskAndWait(const tracked_objects::Location& from_here,
58 const base::Closure& task) {
59 base::WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
60 WaitableEvent::InitialState::NOT_SIGNALED);
61 task_runner()->PostTask(from_here,
62 base::Bind(&PostTaskAndWaitHelper, &event, task));
63 event.Wait();
64 }
65
66 } // namespace base 45 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_io_thread.h ('k') | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698