| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/port.h" | 5 #include "vm/port.h" |
| 6 | 6 |
| 7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/message_handler.h" | 10 #include "vm/message_handler.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 ASSERT(index >= 0); | 210 ASSERT(index >= 0); |
| 211 ASSERT(index < capacity_); | 211 ASSERT(index < capacity_); |
| 212 MessageHandler* handler = map_[index].handler; | 212 MessageHandler* handler = map_[index].handler; |
| 213 ASSERT(map_[index].port != 0); | 213 ASSERT(map_[index].port != 0); |
| 214 ASSERT((handler != NULL) && (handler != deleted_entry_)); | 214 ASSERT((handler != NULL) && (handler != deleted_entry_)); |
| 215 handler->PostMessage(message); | 215 handler->PostMessage(message); |
| 216 return true; | 216 return true; |
| 217 } | 217 } |
| 218 | 218 |
| 219 | 219 |
| 220 bool PortMap::IsLocalPort(Dart_Port id) { |
| 221 MutexLocker ml(mutex_); |
| 222 intptr_t index = FindPort(id); |
| 223 if (index < 0) { |
| 224 // Port does not exist. |
| 225 return false; |
| 226 } |
| 227 |
| 228 MessageHandler* handler = map_[index].handler; |
| 229 return handler->IsCurrentIsolate(); |
| 230 } |
| 231 |
| 232 |
| 220 void PortMap::InitOnce() { | 233 void PortMap::InitOnce() { |
| 221 mutex_ = new Mutex(); | 234 mutex_ = new Mutex(); |
| 222 | 235 |
| 223 static const intptr_t kInitialCapacity = 8; | 236 static const intptr_t kInitialCapacity = 8; |
| 224 // TODO(iposva): Verify whether we want to keep exponentially growing. | 237 // TODO(iposva): Verify whether we want to keep exponentially growing. |
| 225 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); | 238 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); |
| 226 map_ = new Entry[kInitialCapacity]; | 239 map_ = new Entry[kInitialCapacity]; |
| 227 memset(map_, 0, kInitialCapacity * sizeof(Entry)); | 240 memset(map_, 0, kInitialCapacity * sizeof(Entry)); |
| 228 capacity_ = kInitialCapacity; | 241 capacity_ = kInitialCapacity; |
| 229 used_ = 0; | 242 used_ = 0; |
| 230 deleted_ = 0; | 243 deleted_ = 0; |
| 231 } | 244 } |
| 232 | 245 |
| 233 } // namespace dart | 246 } // namespace dart |
| OLD | NEW |