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