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