| 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/public/tests/simple_bindings_support.h" | 5 #include "mojo/public/tests/simple_bindings_support.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 namespace mojo { | 9 namespace mojo { |
| 10 namespace test { | 10 namespace test { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 if (it->callback == callback) { | 36 if (it->callback == callback) { |
| 37 std::list<Waiter>::iterator doomed = it++; | 37 std::list<Waiter>::iterator doomed = it++; |
| 38 waiters_.erase(doomed); | 38 waiters_.erase(doomed); |
| 39 } else { | 39 } else { |
| 40 ++it; | 40 ++it; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SimpleBindingsSupport::Process() { | 45 void SimpleBindingsSupport::Process() { |
| 46 typedef std::pair<AsyncWaitCallback*, MojoResult> Result; | 46 for (;;) { |
| 47 std::list<Result> results; | 47 typedef std::pair<AsyncWaitCallback*, MojoResult> Result; |
| 48 std::list<Result> results; |
| 48 | 49 |
| 49 // TODO(darin): Honor given deadline. | 50 // TODO(darin): Honor given deadline. |
| 50 | 51 |
| 51 std::list<Waiter>::iterator it = waiters_.begin(); | 52 std::list<Waiter>::iterator it = waiters_.begin(); |
| 52 while (it != waiters_.end()) { | 53 while (it != waiters_.end()) { |
| 53 const Waiter& waiter = *it; | 54 const Waiter& waiter = *it; |
| 54 MojoResult result; | 55 MojoResult result; |
| 55 if (IsReady(waiter.handle, waiter.flags, &result)) { | 56 if (IsReady(waiter.handle, waiter.flags, &result)) { |
| 56 results.push_back(std::make_pair(waiter.callback, result)); | 57 results.push_back(std::make_pair(waiter.callback, result)); |
| 57 std::list<Waiter>::iterator doomed = it++; | 58 std::list<Waiter>::iterator doomed = it++; |
| 58 waiters_.erase(doomed); | 59 waiters_.erase(doomed); |
| 59 } else { | 60 } else { |
| 60 ++it; | 61 ++it; |
| 62 } |
| 61 } | 63 } |
| 62 } | |
| 63 | 64 |
| 64 for (std::list<Result>::const_iterator it = results.begin(); | 65 for (std::list<Result>::const_iterator it = results.begin(); |
| 65 it != results.end(); | 66 it != results.end(); |
| 66 ++it) { | 67 ++it) { |
| 67 it->first->OnHandleReady(it->second); | 68 it->first->OnHandleReady(it->second); |
| 69 } |
| 70 if (results.empty()) |
| 71 break; |
| 68 } | 72 } |
| 69 } | 73 } |
| 70 | 74 |
| 71 bool SimpleBindingsSupport::IsReady(Handle handle, MojoWaitFlags flags, | 75 bool SimpleBindingsSupport::IsReady(Handle handle, MojoWaitFlags flags, |
| 72 MojoResult* result) { | 76 MojoResult* result) { |
| 73 *result = Wait(handle, flags, 0); | 77 *result = Wait(handle, flags, 0); |
| 74 return *result != MOJO_RESULT_DEADLINE_EXCEEDED; | 78 return *result != MOJO_RESULT_DEADLINE_EXCEEDED; |
| 75 } | 79 } |
| 76 | 80 |
| 77 } // namespace test | 81 } // namespace test |
| 78 } // namespace mojo | 82 } // namespace mojo |
| OLD | NEW |