OLD | NEW |
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 "mojo/edk/system/test/test_io_thread.h" | 5 #include "mojo/edk/system/test/test_io_thread.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "mojo/edk/util/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
11 | |
12 using mojo::util::AutoResetWaitableEvent; | |
13 | 11 |
14 namespace mojo { | 12 namespace mojo { |
15 namespace system { | 13 namespace system { |
16 namespace test { | 14 namespace test { |
17 | 15 |
18 namespace { | 16 namespace { |
19 | 17 |
20 void PostTaskAndWaitHelper(AutoResetWaitableEvent* event, | 18 void PostTaskAndWaitHelper(base::WaitableEvent* event, |
21 const base::Closure& task) { | 19 const base::Closure& task) { |
22 task.Run(); | 20 task.Run(); |
23 event->Signal(); | 21 event->Signal(); |
24 } | 22 } |
25 | 23 |
26 } // namespace | 24 } // namespace |
27 | 25 |
28 TestIOThread::TestIOThread(StartMode start_mode) | 26 TestIOThread::TestIOThread(StartMode start_mode) |
29 : io_thread_("test_io_thread"), io_thread_started_(false) { | 27 : io_thread_("test_io_thread"), io_thread_started_(false) { |
30 switch (start_mode) { | 28 switch (start_mode) { |
(...skipping 21 matching lines...) Expand all Loading... |
52 // Note: It's okay to call |Stop()| even if the thread isn't running. | 50 // Note: It's okay to call |Stop()| even if the thread isn't running. |
53 io_thread_.Stop(); | 51 io_thread_.Stop(); |
54 io_thread_started_ = false; | 52 io_thread_started_ = false; |
55 } | 53 } |
56 | 54 |
57 void TestIOThread::PostTask(const base::Closure& task) { | 55 void TestIOThread::PostTask(const base::Closure& task) { |
58 task_runner()->PostTask(tracked_objects::Location(), task); | 56 task_runner()->PostTask(tracked_objects::Location(), task); |
59 } | 57 } |
60 | 58 |
61 void TestIOThread::PostTaskAndWait(const base::Closure& task) { | 59 void TestIOThread::PostTaskAndWait(const base::Closure& task) { |
62 AutoResetWaitableEvent event; | 60 base::WaitableEvent event(false, false); |
63 task_runner()->PostTask(tracked_objects::Location(), | 61 task_runner()->PostTask(tracked_objects::Location(), |
64 base::Bind(&PostTaskAndWaitHelper, &event, task)); | 62 base::Bind(&PostTaskAndWaitHelper, &event, task)); |
65 event.Wait(); | 63 event.Wait(); |
66 } | 64 } |
67 | 65 |
68 } // namespace test | 66 } // namespace test |
69 } // namespace system | 67 } // namespace system |
70 } // namespace mojo | 68 } // namespace mojo |
OLD | NEW |