| 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/system/waiter_test_utils.h" | 5 #include "mojo/system/waiter_test_utils.h" |
| 6 | 6 |
| 7 namespace mojo { | 7 namespace mojo { |
| 8 namespace system { | 8 namespace system { |
| 9 namespace test { | 9 namespace test { |
| 10 | 10 |
| 11 SimpleWaiterThread::SimpleWaiterThread(MojoResult* result, uint32_t* context) | 11 SimpleWaiterThread::SimpleWaiterThread(MojoResult* result, uint32_t* context) |
| 12 : base::SimpleThread("waiter_thread"), | 12 : base::SimpleThread("waiter_thread"), |
| 13 result_(result), | 13 result_(result), |
| 14 context_(context) { | 14 context_(context) { |
| 15 waiter_.Init(); | 15 waiter_.Init(); |
| 16 *result_ = -5420734; // Totally invalid result. | 16 *result_ = -5420734; // Totally invalid result. |
| 17 *context_ = 23489023; // "Random". | 17 *context_ = 23489023; // "Random". |
| 18 } | 18 } |
| 19 | 19 |
| 20 SimpleWaiterThread::~SimpleWaiterThread() { | 20 SimpleWaiterThread::~SimpleWaiterThread() { |
| 21 Join(); | 21 Join(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void SimpleWaiterThread::Run() { | 24 void SimpleWaiterThread::Run() { |
| 25 *result_ = waiter_.Wait(MOJO_DEADLINE_INDEFINITE, context_); | 25 *result_ = waiter_.Wait(MOJO_DEADLINE_INDEFINITE, context_); |
| 26 } | 26 } |
| 27 | 27 |
| 28 WaiterThread::WaiterThread(scoped_refptr<Dispatcher> dispatcher, | 28 WaiterThread::WaiterThread(scoped_refptr<Dispatcher> dispatcher, |
| 29 MojoWaitFlags wait_flags, | 29 MojoHandleSignals handle_signals, |
| 30 MojoDeadline deadline, | 30 MojoDeadline deadline, |
| 31 uint32_t context, | 31 uint32_t context, |
| 32 bool* did_wait_out, | 32 bool* did_wait_out, |
| 33 MojoResult* result_out, | 33 MojoResult* result_out, |
| 34 uint32_t* context_out) | 34 uint32_t* context_out) |
| 35 : base::SimpleThread("waiter_thread"), | 35 : base::SimpleThread("waiter_thread"), |
| 36 dispatcher_(dispatcher), | 36 dispatcher_(dispatcher), |
| 37 wait_flags_(wait_flags), | 37 handle_signals_(handle_signals), |
| 38 deadline_(deadline), | 38 deadline_(deadline), |
| 39 context_(context), | 39 context_(context), |
| 40 did_wait_out_(did_wait_out), | 40 did_wait_out_(did_wait_out), |
| 41 result_out_(result_out), | 41 result_out_(result_out), |
| 42 context_out_(context_out) { | 42 context_out_(context_out) { |
| 43 *did_wait_out_ = false; | 43 *did_wait_out_ = false; |
| 44 *result_out_ = -8542346; // Totally invalid result. | 44 *result_out_ = -8542346; // Totally invalid result. |
| 45 *context_out_ = 89023444; // "Random". | 45 *context_out_ = 89023444; // "Random". |
| 46 } | 46 } |
| 47 | 47 |
| 48 WaiterThread::~WaiterThread() { | 48 WaiterThread::~WaiterThread() { |
| 49 Join(); | 49 Join(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void WaiterThread::Run() { | 52 void WaiterThread::Run() { |
| 53 waiter_.Init(); | 53 waiter_.Init(); |
| 54 | 54 |
| 55 *result_out_ = dispatcher_->AddWaiter(&waiter_, wait_flags_, context_); | 55 *result_out_ = dispatcher_->AddWaiter(&waiter_, handle_signals_, context_); |
| 56 if (*result_out_ != MOJO_RESULT_OK) | 56 if (*result_out_ != MOJO_RESULT_OK) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 *did_wait_out_ = true; | 59 *did_wait_out_ = true; |
| 60 *result_out_ = waiter_.Wait(deadline_, context_out_); | 60 *result_out_ = waiter_.Wait(deadline_, context_out_); |
| 61 dispatcher_->RemoveWaiter(&waiter_); | 61 dispatcher_->RemoveWaiter(&waiter_); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace test | 64 } // namespace test |
| 65 } // namespace system | 65 } // namespace system |
| 66 } // namespace mojo | 66 } // namespace mojo |
| OLD | NEW |