| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ports/node.h" | 5 #include "mojo/edk/system/ports/node.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 "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 if (message->num_ports() > 0) { | 948 if (message->num_ports() > 0) { |
| 949 // Note: Another thread could be trying to send the same ports, so we need | 949 // Note: Another thread could be trying to send the same ports, so we need |
| 950 // to ensure that they are ours to send before we mutate their state. | 950 // to ensure that they are ours to send before we mutate their state. |
| 951 | 951 |
| 952 std::vector<scoped_refptr<Port>> ports; | 952 std::vector<scoped_refptr<Port>> ports; |
| 953 ports.resize(message->num_ports()); | 953 ports.resize(message->num_ports()); |
| 954 | 954 |
| 955 { | 955 { |
| 956 for (size_t i = 0; i < message->num_ports(); ++i) { | 956 for (size_t i = 0; i < message->num_ports(); ++i) { |
| 957 ports[i] = GetPort_Locked(message->ports()[i]); | 957 ports[i] = GetPort_Locked(message->ports()[i]); |
| 958 CHECK(ports[i]); |
| 959 |
| 958 ports[i]->lock.Acquire(); | 960 ports[i]->lock.Acquire(); |
| 959 | |
| 960 int error = OK; | 961 int error = OK; |
| 961 if (ports[i]->state != Port::kReceiving) | 962 if (ports[i]->state != Port::kReceiving) |
| 962 error = ERROR_PORT_STATE_UNEXPECTED; | 963 error = ERROR_PORT_STATE_UNEXPECTED; |
| 963 else if (message->ports()[i] == port->peer_port_name) | 964 else if (message->ports()[i] == port->peer_port_name) |
| 964 error = ERROR_PORT_CANNOT_SEND_PEER; | 965 error = ERROR_PORT_CANNOT_SEND_PEER; |
| 965 | 966 |
| 966 if (error != OK) { | 967 if (error != OK) { |
| 967 // Oops, we cannot send this port. | 968 // Oops, we cannot send this port. |
| 968 for (size_t j = 0; j <= i; ++j) | 969 for (size_t j = 0; j <= i; ++j) |
| 969 ports[i]->lock.Release(); | 970 ports[i]->lock.Release(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 | 1116 |
| 1116 if (num_data_bytes) | 1117 if (num_data_bytes) |
| 1117 memcpy(header + 1, data, num_data_bytes); | 1118 memcpy(header + 1, data, num_data_bytes); |
| 1118 | 1119 |
| 1119 return message; | 1120 return message; |
| 1120 } | 1121 } |
| 1121 | 1122 |
| 1122 } // namespace ports | 1123 } // namespace ports |
| 1123 } // namespace edk | 1124 } // namespace edk |
| 1124 } // namespace mojo | 1125 } // namespace mojo |
| OLD | NEW |