tuple: update to make use of C++11
[chromium-blink-merge.git] / mojo / edk / system / waiter_test_utils.cc
blobea243ed1406785ac2479b55b793cf5c5fcc1357a
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.
5 #include "mojo/edk/system/waiter_test_utils.h"
7 namespace mojo {
8 namespace system {
9 namespace test {
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".
18 SimpleWaiterThread::~SimpleWaiterThread() {
19 Join();
22 void SimpleWaiterThread::Run() {
23 *result_ = waiter_.Wait(MOJO_DEADLINE_INDEFINITE, context_);
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);
51 WaiterThread::~WaiterThread() {
52 Join();
55 void WaiterThread::Run() {
56 waiter_.Init();
58 *result_out_ = dispatcher_->AddAwakable(&waiter_, handle_signals_, context_,
59 signals_state_out_);
60 if (*result_out_ != MOJO_RESULT_OK)
61 return;
63 *did_wait_out_ = true;
64 *result_out_ = waiter_.Wait(deadline_, context_out_);
65 dispatcher_->RemoveAwakable(&waiter_, signals_state_out_);
68 } // namespace test
69 } // namespace system
70 } // namespace mojo