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/message_pipe_dispatcher.h" | 5 #include "mojo/edk/system/message_pipe_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/edk/system/configuration.h" | 8 #include "mojo/edk/system/configuration.h" |
9 #include "mojo/edk/system/local_message_pipe_endpoint.h" | 9 #include "mojo/edk/system/local_message_pipe_endpoint.h" |
10 #include "mojo/edk/system/memory.h" | 10 #include "mojo/edk/system/memory.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) { | 99 MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) { |
100 } | 100 } |
101 | 101 |
102 MessagePipeDispatcher::~MessagePipeDispatcher() { | 102 MessagePipeDispatcher::~MessagePipeDispatcher() { |
103 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. | 103 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. |
104 DCHECK(!message_pipe_); | 104 DCHECK(!message_pipe_); |
105 } | 105 } |
106 | 106 |
107 MessagePipe* MessagePipeDispatcher::GetMessagePipeNoLock() const { | 107 MessagePipe* MessagePipeDispatcher::GetMessagePipeNoLock() const { |
108 lock().AssertAcquired(); | 108 mutex().AssertHeld(); |
109 return message_pipe_.get(); | 109 return message_pipe_.get(); |
110 } | 110 } |
111 | 111 |
112 unsigned MessagePipeDispatcher::GetPortNoLock() const { | 112 unsigned MessagePipeDispatcher::GetPortNoLock() const { |
113 lock().AssertAcquired(); | 113 mutex().AssertHeld(); |
114 return port_; | 114 return port_; |
115 } | 115 } |
116 | 116 |
117 void MessagePipeDispatcher::CancelAllAwakablesNoLock() { | 117 void MessagePipeDispatcher::CancelAllAwakablesNoLock() { |
118 lock().AssertAcquired(); | 118 mutex().AssertHeld(); |
119 message_pipe_->CancelAllAwakables(port_); | 119 message_pipe_->CancelAllAwakables(port_); |
120 } | 120 } |
121 | 121 |
122 void MessagePipeDispatcher::CloseImplNoLock() { | 122 void MessagePipeDispatcher::CloseImplNoLock() { |
123 lock().AssertAcquired(); | 123 mutex().AssertHeld(); |
124 message_pipe_->Close(port_); | 124 message_pipe_->Close(port_); |
125 message_pipe_ = nullptr; | 125 message_pipe_ = nullptr; |
126 port_ = kInvalidPort; | 126 port_ = kInvalidPort; |
127 } | 127 } |
128 | 128 |
129 scoped_refptr<Dispatcher> | 129 scoped_refptr<Dispatcher> |
130 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 130 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
131 lock().AssertAcquired(); | 131 mutex().AssertHeld(); |
132 | 132 |
133 // TODO(vtl): Currently, there are no options, so we just use | 133 // TODO(vtl): Currently, there are no options, so we just use |
134 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options | 134 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options |
135 // too. | 135 // too. |
136 scoped_refptr<MessagePipeDispatcher> rv = Create(kDefaultCreateOptions); | 136 scoped_refptr<MessagePipeDispatcher> rv = Create(kDefaultCreateOptions); |
137 rv->Init(message_pipe_, port_); | 137 rv->Init(message_pipe_, port_); |
138 message_pipe_ = nullptr; | 138 message_pipe_ = nullptr; |
139 port_ = kInvalidPort; | 139 port_ = kInvalidPort; |
140 return scoped_refptr<Dispatcher>(rv.get()); | 140 return scoped_refptr<Dispatcher>(rv.get()); |
141 } | 141 } |
142 | 142 |
143 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( | 143 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( |
144 UserPointer<const void> bytes, | 144 UserPointer<const void> bytes, |
145 uint32_t num_bytes, | 145 uint32_t num_bytes, |
146 std::vector<DispatcherTransport>* transports, | 146 std::vector<DispatcherTransport>* transports, |
147 MojoWriteMessageFlags flags) { | 147 MojoWriteMessageFlags flags) { |
148 DCHECK(!transports || | 148 DCHECK(!transports || |
149 (transports->size() > 0 && | 149 (transports->size() > 0 && |
150 transports->size() <= GetConfiguration().max_message_num_handles)); | 150 transports->size() <= GetConfiguration().max_message_num_handles)); |
151 | 151 |
152 lock().AssertAcquired(); | 152 mutex().AssertHeld(); |
153 | 153 |
154 if (num_bytes > GetConfiguration().max_message_num_bytes) | 154 if (num_bytes > GetConfiguration().max_message_num_bytes) |
155 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 155 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
156 | 156 |
157 return message_pipe_->WriteMessage(port_, bytes, num_bytes, transports, | 157 return message_pipe_->WriteMessage(port_, bytes, num_bytes, transports, |
158 flags); | 158 flags); |
159 } | 159 } |
160 | 160 |
161 MojoResult MessagePipeDispatcher::ReadMessageImplNoLock( | 161 MojoResult MessagePipeDispatcher::ReadMessageImplNoLock( |
162 UserPointer<void> bytes, | 162 UserPointer<void> bytes, |
163 UserPointer<uint32_t> num_bytes, | 163 UserPointer<uint32_t> num_bytes, |
164 DispatcherVector* dispatchers, | 164 DispatcherVector* dispatchers, |
165 uint32_t* num_dispatchers, | 165 uint32_t* num_dispatchers, |
166 MojoReadMessageFlags flags) { | 166 MojoReadMessageFlags flags) { |
167 lock().AssertAcquired(); | 167 mutex().AssertHeld(); |
168 return message_pipe_->ReadMessage(port_, bytes, num_bytes, dispatchers, | 168 return message_pipe_->ReadMessage(port_, bytes, num_bytes, dispatchers, |
169 num_dispatchers, flags); | 169 num_dispatchers, flags); |
170 } | 170 } |
171 | 171 |
172 HandleSignalsState MessagePipeDispatcher::GetHandleSignalsStateImplNoLock() | 172 HandleSignalsState MessagePipeDispatcher::GetHandleSignalsStateImplNoLock() |
173 const { | 173 const { |
174 lock().AssertAcquired(); | 174 mutex().AssertHeld(); |
175 return message_pipe_->GetHandleSignalsState(port_); | 175 return message_pipe_->GetHandleSignalsState(port_); |
176 } | 176 } |
177 | 177 |
178 MojoResult MessagePipeDispatcher::AddAwakableImplNoLock( | 178 MojoResult MessagePipeDispatcher::AddAwakableImplNoLock( |
179 Awakable* awakable, | 179 Awakable* awakable, |
180 MojoHandleSignals signals, | 180 MojoHandleSignals signals, |
181 uint32_t context, | 181 uint32_t context, |
182 HandleSignalsState* signals_state) { | 182 HandleSignalsState* signals_state) { |
183 lock().AssertAcquired(); | 183 mutex().AssertHeld(); |
184 return message_pipe_->AddAwakable(port_, awakable, signals, context, | 184 return message_pipe_->AddAwakable(port_, awakable, signals, context, |
185 signals_state); | 185 signals_state); |
186 } | 186 } |
187 | 187 |
188 void MessagePipeDispatcher::RemoveAwakableImplNoLock( | 188 void MessagePipeDispatcher::RemoveAwakableImplNoLock( |
189 Awakable* awakable, | 189 Awakable* awakable, |
190 HandleSignalsState* signals_state) { | 190 HandleSignalsState* signals_state) { |
191 lock().AssertAcquired(); | 191 mutex().AssertHeld(); |
192 message_pipe_->RemoveAwakable(port_, awakable, signals_state); | 192 message_pipe_->RemoveAwakable(port_, awakable, signals_state); |
193 } | 193 } |
194 | 194 |
195 void MessagePipeDispatcher::StartSerializeImplNoLock( | 195 void MessagePipeDispatcher::StartSerializeImplNoLock( |
196 Channel* channel, | 196 Channel* channel, |
197 size_t* max_size, | 197 size_t* max_size, |
198 size_t* max_platform_handles) { | 198 size_t* max_platform_handles) { |
199 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 199 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
200 return message_pipe_->StartSerialize(port_, channel, max_size, | 200 return message_pipe_->StartSerialize(port_, channel, max_size, |
201 max_platform_handles); | 201 max_platform_handles); |
(...skipping 17 matching lines...) Expand all Loading... |
219 | 219 |
220 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( | 220 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( |
221 DispatcherTransport transport) | 221 DispatcherTransport transport) |
222 : DispatcherTransport(transport) { | 222 : DispatcherTransport(transport) { |
223 DCHECK_EQ(message_pipe_dispatcher()->GetType(), | 223 DCHECK_EQ(message_pipe_dispatcher()->GetType(), |
224 Dispatcher::Type::MESSAGE_PIPE); | 224 Dispatcher::Type::MESSAGE_PIPE); |
225 } | 225 } |
226 | 226 |
227 } // namespace system | 227 } // namespace system |
228 } // namespace mojo | 228 } // namespace mojo |
OLD | NEW |