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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 waiters_.erase(doomed); | 42 waiters_.erase(doomed); |
43 } else { | 43 } else { |
44 ++it; | 44 ++it; |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 delete waiter; | 48 delete waiter; |
49 } | 49 } |
50 | 50 |
51 void SimpleBindingsSupport::Process() { | 51 void SimpleBindingsSupport::Process() { |
52 typedef std::pair<AsyncWaitCallback*, MojoResult> Result; | 52 for (;;) { |
53 std::list<Result> results; | 53 typedef std::pair<AsyncWaitCallback*, MojoResult> Result; |
| 54 std::list<Result> results; |
54 | 55 |
55 WaiterList::iterator it = waiters_.begin(); | 56 WaiterList::iterator it = waiters_.begin(); |
56 while (it != waiters_.end()) { | 57 while (it != waiters_.end()) { |
57 Waiter* waiter = *it; | 58 Waiter* waiter = *it; |
58 MojoResult result; | 59 MojoResult result; |
59 if (IsReady(waiter->handle, waiter->flags, &result)) { | 60 if (IsReady(waiter->handle, waiter->flags, &result)) { |
60 results.push_back(std::make_pair(waiter->callback, result)); | 61 results.push_back(std::make_pair(waiter->callback, result)); |
61 WaiterList::iterator doomed = it++; | 62 WaiterList::iterator doomed = it++; |
62 waiters_.erase(doomed); | 63 waiters_.erase(doomed); |
63 delete waiter; | 64 delete waiter; |
64 } else { | 65 } else { |
65 ++it; | 66 ++it; |
| 67 } |
66 } | 68 } |
67 } | |
68 | 69 |
69 for (std::list<Result>::const_iterator it = results.begin(); | 70 for (std::list<Result>::const_iterator it = results.begin(); |
70 it != results.end(); | 71 it != results.end(); |
71 ++it) { | 72 ++it) { |
72 it->first->OnHandleReady(it->second); | 73 it->first->OnHandleReady(it->second); |
| 74 } |
| 75 if (results.empty()) |
| 76 break; |
73 } | 77 } |
74 } | 78 } |
75 | 79 |
76 bool SimpleBindingsSupport::IsReady(Handle handle, MojoWaitFlags flags, | 80 bool SimpleBindingsSupport::IsReady(Handle handle, MojoWaitFlags flags, |
77 MojoResult* result) { | 81 MojoResult* result) { |
78 *result = Wait(handle, flags, 0); | 82 *result = Wait(handle, flags, 0); |
79 return *result != MOJO_RESULT_DEADLINE_EXCEEDED; | 83 return *result != MOJO_RESULT_DEADLINE_EXCEEDED; |
80 } | 84 } |
81 | 85 |
82 } // namespace test | 86 } // namespace test |
83 } // namespace mojo | 87 } // namespace mojo |
OLD | NEW |