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/edk/system/local_message_pipe_endpoint.h" | 5 #include "mojo/edk/system/local_message_pipe_endpoint.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/edk/system/dispatcher.h" | 10 #include "mojo/edk/system/dispatcher.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 bool LocalMessagePipeEndpoint::OnPeerClose() { | 29 bool LocalMessagePipeEndpoint::OnPeerClose() { |
30 DCHECK(is_open_); | 30 DCHECK(is_open_); |
31 DCHECK(is_peer_open_); | 31 DCHECK(is_peer_open_); |
32 | 32 |
33 HandleSignalsState old_state = GetHandleSignalsState(); | 33 HandleSignalsState old_state = GetHandleSignalsState(); |
34 is_peer_open_ = false; | 34 is_peer_open_ = false; |
35 HandleSignalsState new_state = GetHandleSignalsState(); | 35 HandleSignalsState new_state = GetHandleSignalsState(); |
36 | 36 |
37 if (!new_state.equals(old_state)) | 37 if (!new_state.equals(old_state)) |
38 waiter_list_.AwakeWaitersForStateChange(new_state); | 38 awakable_list_.AwakeForStateChange(new_state); |
39 | 39 |
40 return true; | 40 return true; |
41 } | 41 } |
42 | 42 |
43 void LocalMessagePipeEndpoint::EnqueueMessage( | 43 void LocalMessagePipeEndpoint::EnqueueMessage( |
44 scoped_ptr<MessageInTransit> message) { | 44 scoped_ptr<MessageInTransit> message) { |
45 DCHECK(is_open_); | 45 DCHECK(is_open_); |
46 DCHECK(is_peer_open_); | 46 DCHECK(is_peer_open_); |
47 | 47 |
48 bool was_empty = message_queue_.IsEmpty(); | 48 bool was_empty = message_queue_.IsEmpty(); |
49 message_queue_.AddMessage(message.Pass()); | 49 message_queue_.AddMessage(message.Pass()); |
50 if (was_empty) | 50 if (was_empty) |
51 waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsState()); | 51 awakable_list_.AwakeForStateChange(GetHandleSignalsState()); |
52 } | 52 } |
53 | 53 |
54 void LocalMessagePipeEndpoint::Close() { | 54 void LocalMessagePipeEndpoint::Close() { |
55 DCHECK(is_open_); | 55 DCHECK(is_open_); |
56 is_open_ = false; | 56 is_open_ = false; |
57 message_queue_.Clear(); | 57 message_queue_.Clear(); |
58 } | 58 } |
59 | 59 |
60 void LocalMessagePipeEndpoint::CancelAllWaiters() { | 60 void LocalMessagePipeEndpoint::CancelAllAwakables() { |
61 DCHECK(is_open_); | 61 DCHECK(is_open_); |
62 waiter_list_.CancelAllWaiters(); | 62 awakable_list_.CancelAll(); |
63 } | 63 } |
64 | 64 |
65 MojoResult LocalMessagePipeEndpoint::ReadMessage( | 65 MojoResult LocalMessagePipeEndpoint::ReadMessage( |
66 UserPointer<void> bytes, | 66 UserPointer<void> bytes, |
67 UserPointer<uint32_t> num_bytes, | 67 UserPointer<uint32_t> num_bytes, |
68 DispatcherVector* dispatchers, | 68 DispatcherVector* dispatchers, |
69 uint32_t* num_dispatchers, | 69 uint32_t* num_dispatchers, |
70 MojoReadMessageFlags flags) { | 70 MojoReadMessageFlags flags) { |
71 DCHECK(is_open_); | 71 DCHECK(is_open_); |
72 DCHECK(!dispatchers || dispatchers->empty()); | 72 DCHECK(!dispatchers || dispatchers->empty()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 message = nullptr; | 111 message = nullptr; |
112 | 112 |
113 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { | 113 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { |
114 message_queue_.DiscardMessage(); | 114 message_queue_.DiscardMessage(); |
115 | 115 |
116 // Now it's empty, thus no longer readable. | 116 // Now it's empty, thus no longer readable. |
117 if (message_queue_.IsEmpty()) { | 117 if (message_queue_.IsEmpty()) { |
118 // It's currently not possible to wait for non-readability, but we should | 118 // It's currently not possible to wait for non-readability, but we should |
119 // do the state change anyway. | 119 // do the state change anyway. |
120 waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsState()); | 120 awakable_list_.AwakeForStateChange(GetHandleSignalsState()); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 if (!enough_space) | 124 if (!enough_space) |
125 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 125 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
126 | 126 |
127 return MOJO_RESULT_OK; | 127 return MOJO_RESULT_OK; |
128 } | 128 } |
129 | 129 |
130 HandleSignalsState LocalMessagePipeEndpoint::GetHandleSignalsState() const { | 130 HandleSignalsState LocalMessagePipeEndpoint::GetHandleSignalsState() const { |
131 HandleSignalsState rv; | 131 HandleSignalsState rv; |
132 if (!message_queue_.IsEmpty()) { | 132 if (!message_queue_.IsEmpty()) { |
133 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 133 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
134 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 134 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
135 } | 135 } |
136 if (is_peer_open_) { | 136 if (is_peer_open_) { |
137 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 137 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
138 rv.satisfiable_signals |= | 138 rv.satisfiable_signals |= |
139 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; | 139 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; |
140 } else { | 140 } else { |
141 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 141 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
142 } | 142 } |
143 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 143 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
144 return rv; | 144 return rv; |
145 } | 145 } |
146 | 146 |
147 MojoResult LocalMessagePipeEndpoint::AddWaiter( | 147 MojoResult LocalMessagePipeEndpoint::AddAwakable( |
148 Waiter* waiter, | 148 Awakable* awakable, |
149 MojoHandleSignals signals, | 149 MojoHandleSignals signals, |
150 uint32_t context, | 150 uint32_t context, |
151 HandleSignalsState* signals_state) { | 151 HandleSignalsState* signals_state) { |
152 DCHECK(is_open_); | 152 DCHECK(is_open_); |
153 | 153 |
154 HandleSignalsState state = GetHandleSignalsState(); | 154 HandleSignalsState state = GetHandleSignalsState(); |
155 if (state.satisfies(signals)) { | 155 if (state.satisfies(signals)) { |
156 if (signals_state) | 156 if (signals_state) |
157 *signals_state = state; | 157 *signals_state = state; |
158 return MOJO_RESULT_ALREADY_EXISTS; | 158 return MOJO_RESULT_ALREADY_EXISTS; |
159 } | 159 } |
160 if (!state.can_satisfy(signals)) { | 160 if (!state.can_satisfy(signals)) { |
161 if (signals_state) | 161 if (signals_state) |
162 *signals_state = state; | 162 *signals_state = state; |
163 return MOJO_RESULT_FAILED_PRECONDITION; | 163 return MOJO_RESULT_FAILED_PRECONDITION; |
164 } | 164 } |
165 | 165 |
166 waiter_list_.AddWaiter(waiter, signals, context); | 166 awakable_list_.Add(awakable, signals, context); |
167 return MOJO_RESULT_OK; | 167 return MOJO_RESULT_OK; |
168 } | 168 } |
169 | 169 |
170 void LocalMessagePipeEndpoint::RemoveWaiter(Waiter* waiter, | 170 void LocalMessagePipeEndpoint::RemoveAwakable( |
171 HandleSignalsState* signals_state) { | 171 Awakable* awakable, |
| 172 HandleSignalsState* signals_state) { |
172 DCHECK(is_open_); | 173 DCHECK(is_open_); |
173 waiter_list_.RemoveWaiter(waiter); | 174 awakable_list_.Remove(awakable); |
174 if (signals_state) | 175 if (signals_state) |
175 *signals_state = GetHandleSignalsState(); | 176 *signals_state = GetHandleSignalsState(); |
176 } | 177 } |
177 | 178 |
178 } // namespace system | 179 } // namespace system |
179 } // namespace mojo | 180 } // namespace mojo |
OLD | NEW |