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