OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/system/waiter_test_utils.h" | |
6 | |
7 namespace mojo { | |
8 namespace system { | |
9 namespace test { | |
10 | |
11 SimpleWaiterThread::SimpleWaiterThread(MojoResult* result, uint32_t* context) | |
12 : base::SimpleThread("waiter_thread"), result_(result), context_(context) { | |
13 waiter_.Init(); | |
14 *result_ = -5420734; // Totally invalid result. | |
15 *context_ = 23489023; // "Random". | |
16 } | |
17 | |
18 SimpleWaiterThread::~SimpleWaiterThread() { | |
19 Join(); | |
20 } | |
21 | |
22 void SimpleWaiterThread::Run() { | |
23 *result_ = waiter_.Wait(MOJO_DEADLINE_INDEFINITE, context_); | |
24 } | |
25 | |
26 WaiterThread::WaiterThread(scoped_refptr<Dispatcher> dispatcher, | |
27 MojoHandleSignals handle_signals, | |
28 MojoDeadline deadline, | |
29 uint32_t context, | |
30 bool* did_wait_out, | |
31 MojoResult* result_out, | |
32 uint32_t* context_out, | |
33 HandleSignalsState* signals_state_out) | |
34 : base::SimpleThread("waiter_thread"), | |
35 dispatcher_(dispatcher), | |
36 handle_signals_(handle_signals), | |
37 deadline_(deadline), | |
38 context_(context), | |
39 did_wait_out_(did_wait_out), | |
40 result_out_(result_out), | |
41 context_out_(context_out), | |
42 signals_state_out_(signals_state_out) { | |
43 *did_wait_out_ = false; | |
44 // Initialize these with invalid results (so that we'll be sure to catch any | |
45 // case where they're not set). | |
46 *result_out_ = -8542346; | |
47 *context_out_ = 89023444; | |
48 *signals_state_out_ = HandleSignalsState(~0u, ~0u); | |
49 } | |
50 | |
51 WaiterThread::~WaiterThread() { | |
52 Join(); | |
53 } | |
54 | |
55 void WaiterThread::Run() { | |
56 waiter_.Init(); | |
57 | |
58 *result_out_ = dispatcher_->AddWaiter( | |
59 &waiter_, handle_signals_, context_, signals_state_out_); | |
60 if (*result_out_ != MOJO_RESULT_OK) | |
61 return; | |
62 | |
63 *did_wait_out_ = true; | |
64 *result_out_ = waiter_.Wait(deadline_, context_out_); | |
65 dispatcher_->RemoveWaiter(&waiter_, signals_state_out_); | |
66 } | |
67 | |
68 } // namespace test | |
69 } // namespace system | |
70 } // namespace mojo | |
OLD | NEW |