| 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/system/core.h" | 5 #include "mojo/system/core.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 UserPointer<const void> bytes, | 193 UserPointer<const void> bytes, |
| 194 uint32_t num_bytes, | 194 uint32_t num_bytes, |
| 195 UserPointer<const MojoHandle> handles, | 195 UserPointer<const MojoHandle> handles, |
| 196 uint32_t num_handles, | 196 uint32_t num_handles, |
| 197 MojoWriteMessageFlags flags) { | 197 MojoWriteMessageFlags flags) { |
| 198 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle)); | 198 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle)); |
| 199 if (!dispatcher) | 199 if (!dispatcher) |
| 200 return MOJO_RESULT_INVALID_ARGUMENT; | 200 return MOJO_RESULT_INVALID_ARGUMENT; |
| 201 | 201 |
| 202 // Easy case: not sending any handles. | 202 // Easy case: not sending any handles. |
| 203 if (num_handles == 0) { | 203 if (num_handles == 0) |
| 204 return dispatcher->WriteMessage(bytes.GetPointerUnsafe(), num_bytes, NULL, | 204 return dispatcher->WriteMessage(bytes, num_bytes, NULL, flags); |
| 205 flags); | |
| 206 } | |
| 207 | 205 |
| 208 // We have to handle |handles| here, since we have to mark them busy in the | 206 // We have to handle |handles| here, since we have to mark them busy in the |
| 209 // global handle table. We can't delegate this to the dispatcher, since the | 207 // global handle table. We can't delegate this to the dispatcher, since the |
| 210 // handle table lock must be acquired before the dispatcher lock. | 208 // handle table lock must be acquired before the dispatcher lock. |
| 211 // | 209 // |
| 212 // (This leads to an oddity: |handles|/|num_handles| are always verified for | 210 // (This leads to an oddity: |handles|/|num_handles| are always verified for |
| 213 // validity, even for dispatchers that don't support |WriteMessage()| and will | 211 // validity, even for dispatchers that don't support |WriteMessage()| and will |
| 214 // simply return failure unconditionally. It also breaks the usual | 212 // simply return failure unconditionally. It also breaks the usual |
| 215 // left-to-right verification order of arguments.) | 213 // left-to-right verification order of arguments.) |
| 216 if (num_handles > kMaxMessageNumHandles) | 214 if (num_handles > kMaxMessageNumHandles) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 230 // handles from the handle table. | 228 // handles from the handle table. |
| 231 { | 229 { |
| 232 base::AutoLock locker(handle_table_lock_); | 230 base::AutoLock locker(handle_table_lock_); |
| 233 MojoResult result = handle_table_.MarkBusyAndStartTransport( | 231 MojoResult result = handle_table_.MarkBusyAndStartTransport( |
| 234 message_pipe_handle, handles_reader.GetPointer(), num_handles, | 232 message_pipe_handle, handles_reader.GetPointer(), num_handles, |
| 235 &transports); | 233 &transports); |
| 236 if (result != MOJO_RESULT_OK) | 234 if (result != MOJO_RESULT_OK) |
| 237 return result; | 235 return result; |
| 238 } | 236 } |
| 239 | 237 |
| 240 MojoResult rv = dispatcher->WriteMessage(bytes.GetPointerUnsafe(), num_bytes, | 238 MojoResult rv = dispatcher->WriteMessage(bytes, num_bytes, &transports, |
| 241 &transports, flags); | 239 flags); |
| 242 | 240 |
| 243 // We need to release the dispatcher locks before we take the handle table | 241 // We need to release the dispatcher locks before we take the handle table |
| 244 // lock. | 242 // lock. |
| 245 for (uint32_t i = 0; i < num_handles; i++) | 243 for (uint32_t i = 0; i < num_handles; i++) |
| 246 transports[i].End(); | 244 transports[i].End(); |
| 247 | 245 |
| 248 { | 246 { |
| 249 base::AutoLock locker(handle_table_lock_); | 247 base::AutoLock locker(handle_table_lock_); |
| 250 if (rv == MOJO_RESULT_OK) { | 248 if (rv == MOJO_RESULT_OK) { |
| 251 handle_table_.RemoveBusyHandles(handles_reader.GetPointer(), num_handles); | 249 handle_table_.RemoveBusyHandles(handles_reader.GetPointer(), num_handles); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be | 557 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be |
| 560 // destroyed, but this would still be required if the waiter were in TLS.) | 558 // destroyed, but this would still be required if the waiter were in TLS.) |
| 561 for (i = 0; i < num_added; i++) | 559 for (i = 0; i < num_added; i++) |
| 562 dispatchers[i]->RemoveWaiter(&waiter); | 560 dispatchers[i]->RemoveWaiter(&waiter); |
| 563 | 561 |
| 564 return rv; | 562 return rv; |
| 565 } | 563 } |
| 566 | 564 |
| 567 } // namespace system | 565 } // namespace system |
| 568 } // namespace mojo | 566 } // namespace mojo |
| OLD | NEW |