Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: runtime/vm/port.cc

Issue 8588040: Add a mid-sized integration test for the Dart Embedding Api which (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 #include "vm/utils.h" 9 #include "vm/utils.h"
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } else if (empty < deleted_) { 83 } else if (empty < deleted_) {
84 // Rehash without growing the table to flush the deleted slots out of the 84 // Rehash without growing the table to flush the deleted slots out of the
85 // map. 85 // map.
86 Rehash(capacity_); 86 Rehash(capacity_);
87 } 87 }
88 } 88 }
89 89
90 90
91 Dart_Port PortMap::CreatePort() { 91 Dart_Port PortMap::CreatePort() {
92 Isolate* isolate = Isolate::Current(); 92 Isolate* isolate = Isolate::Current();
93
94 MutexLocker ml(mutex_); 93 MutexLocker ml(mutex_);
95 94
96 Entry entry; 95 Entry entry;
97 entry.port = AllocatePort(); 96 entry.port = AllocatePort();
98 entry.isolate = isolate; 97 entry.isolate = isolate;
99 98
100 // Search for the first unused slot. Make use of the knowledge that here is 99 // Search for the first unused slot. Make use of the knowledge that here is
101 // currently no port with this id in the port map. 100 // currently no port with this id in the port map.
102 ASSERT(FindPort(entry.port) < 0); 101 ASSERT(FindPort(entry.port) < 0);
103 intptr_t index = entry.port % capacity_; 102 intptr_t index = entry.port % capacity_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Notify the embedder that this port is closed. 154 // Notify the embedder that this port is closed.
156 Dart_ClosePortCallback callback = isolate->close_port_callback(); 155 Dart_ClosePortCallback callback = isolate->close_port_callback();
157 ASSERT(callback); 156 ASSERT(callback);
158 ASSERT(port != kCloseAllPorts); 157 ASSERT(port != kCloseAllPorts);
159 (*callback)(isolate, port); 158 (*callback)(isolate, port);
160 } 159 }
161 160
162 161
163 void PortMap::ClosePorts() { 162 void PortMap::ClosePorts() {
164 Isolate* isolate = Isolate::Current(); 163 Isolate* isolate = Isolate::Current();
164 if (isolate->active_ports() == 0) {
165 return;
166 }
165 { 167 {
166 MutexLocker ml(mutex_); 168 MutexLocker ml(mutex_);
167 for (intptr_t i = 0; i < capacity_; i++) { 169 for (intptr_t i = 0; i < capacity_; i++) {
168 if (map_[i].isolate == isolate) { 170 if (map_[i].isolate == isolate) {
169 // Mark the slot as deleted. 171 // Mark the slot as deleted.
170 map_[i].port = 0; 172 map_[i].port = 0;
171 map_[i].isolate = deleted_entry_; 173 map_[i].isolate = deleted_entry_;
172 isolate->decrement_active_ports(); 174 isolate->decrement_active_ports();
173 175
174 used_--; 176 used_--;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); 227 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity));
226 map_ = new Entry[kInitialCapacity]; 228 map_ = new Entry[kInitialCapacity];
227 memset(map_, 0, kInitialCapacity * sizeof(Entry)); 229 memset(map_, 0, kInitialCapacity * sizeof(Entry));
228 capacity_ = kInitialCapacity; 230 capacity_ = kInitialCapacity;
229 used_ = 0; 231 used_ = 0;
230 deleted_ = 0; 232 deleted_ = 0;
231 } 233 }
232 234
233 235
234 } // namespace dart 236 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698