| 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/thread.h" | 10 #include "vm/thread.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DECLARE_FLAG(bool, trace_isolates); |
| 14 | 15 |
| 15 Mutex* PortMap::mutex_ = NULL; | 16 Mutex* PortMap::mutex_ = NULL; |
| 16 | 17 |
| 17 PortMap::Entry* PortMap::map_ = NULL; | 18 PortMap::Entry* PortMap::map_ = NULL; |
| 18 Isolate* PortMap::deleted_entry_ = reinterpret_cast<Isolate*>(1); | 19 Isolate* PortMap::deleted_entry_ = reinterpret_cast<Isolate*>(1); |
| 19 intptr_t PortMap::capacity_ = 0; | 20 intptr_t PortMap::capacity_ = 0; |
| 20 intptr_t PortMap::used_ = 0; | 21 intptr_t PortMap::used_ = 0; |
| 21 intptr_t PortMap::deleted_ = 0; | 22 intptr_t PortMap::deleted_ = 0; |
| 22 | 23 |
| 23 Dart_Port PortMap::next_port_ = 7111; | 24 Dart_Port PortMap::next_port_ = 7111; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 ASSERT(index < capacity_); | 213 ASSERT(index < capacity_); |
| 213 Isolate* isolate = map_[index].isolate; | 214 Isolate* isolate = map_[index].isolate; |
| 214 ASSERT(map_[index].port != 0); | 215 ASSERT(map_[index].port != 0); |
| 215 ASSERT((isolate != NULL) && (isolate != deleted_entry_)); | 216 ASSERT((isolate != NULL) && (isolate != deleted_entry_)); |
| 216 | 217 |
| 217 // Delegate message delivery to the embedder. | 218 // Delegate message delivery to the embedder. |
| 218 Dart_PostMessageCallback callback = isolate->post_message_callback(); | 219 Dart_PostMessageCallback callback = isolate->post_message_callback(); |
| 219 ASSERT(callback); | 220 ASSERT(callback); |
| 220 bool result = | 221 bool result = |
| 221 (*callback)(Api::CastIsolate(isolate), dest_port, reply_port, message); | 222 (*callback)(Api::CastIsolate(isolate), dest_port, reply_port, message); |
| 222 | 223 if (FLAG_trace_isolates) { |
| 224 const char* source_name = "<native code>"; |
| 225 Isolate* source_isolate = Isolate::Current(); |
| 226 if (source_isolate) { |
| 227 source_name = source_isolate->name(); |
| 228 } |
| 229 OS::Print("[>] Posting message:\n" |
| 230 "\tsource: %s\n" |
| 231 "\treply_port: %lld\n" |
| 232 "\tdest: %s\n" |
| 233 "\tdest_port: %lld\n", |
| 234 source_name, reply_port, isolate->name(), dest_port); |
| 235 } |
| 223 mutex_->Unlock(); | 236 mutex_->Unlock(); |
| 224 return result; | 237 return result; |
| 225 } | 238 } |
| 226 | 239 |
| 227 | 240 |
| 228 void PortMap::InitOnce() { | 241 void PortMap::InitOnce() { |
| 229 mutex_ = new Mutex(); | 242 mutex_ = new Mutex(); |
| 230 | 243 |
| 231 static const intptr_t kInitialCapacity = 8; | 244 static const intptr_t kInitialCapacity = 8; |
| 232 // TODO(iposva): Verify whether we want to keep exponentially growing. | 245 // TODO(iposva): Verify whether we want to keep exponentially growing. |
| 233 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); | 246 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); |
| 234 map_ = new Entry[kInitialCapacity]; | 247 map_ = new Entry[kInitialCapacity]; |
| 235 memset(map_, 0, kInitialCapacity * sizeof(Entry)); | 248 memset(map_, 0, kInitialCapacity * sizeof(Entry)); |
| 236 capacity_ = kInitialCapacity; | 249 capacity_ = kInitialCapacity; |
| 237 used_ = 0; | 250 used_ = 0; |
| 238 deleted_ = 0; | 251 deleted_ = 0; |
| 239 } | 252 } |
| 240 | 253 |
| 241 | 254 |
| 242 } // namespace dart | 255 } // namespace dart |
| OLD | NEW |