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

Side by Side Diff: vm/port.cc

Issue 9618034: - Fix new/free mismatch. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 10 #include "vm/message.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 MaintainInvariants(); 197 MaintainInvariants();
198 } 198 }
199 handler->CloseAllPorts(); 199 handler->CloseAllPorts();
200 } 200 }
201 201
202 202
203 bool PortMap::PostMessage(Message* message) { 203 bool PortMap::PostMessage(Message* message) {
204 MutexLocker ml(mutex_); 204 MutexLocker ml(mutex_);
205 intptr_t index = FindPort(message->dest_port()); 205 intptr_t index = FindPort(message->dest_port());
206 if (index < 0) { 206 if (index < 0) {
207 free(message); 207 delete message;
208 return false; 208 return false;
209 } 209 }
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 void PortMap::InitOnce() { 220 void PortMap::InitOnce() {
221 mutex_ = new Mutex(); 221 mutex_ = new Mutex();
222 222
223 static const intptr_t kInitialCapacity = 8; 223 static const intptr_t kInitialCapacity = 8;
224 // TODO(iposva): Verify whether we want to keep exponentially growing. 224 // TODO(iposva): Verify whether we want to keep exponentially growing.
225 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); 225 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity));
226 map_ = new Entry[kInitialCapacity]; 226 map_ = new Entry[kInitialCapacity];
227 memset(map_, 0, kInitialCapacity * sizeof(Entry)); 227 memset(map_, 0, kInitialCapacity * sizeof(Entry));
228 capacity_ = kInitialCapacity; 228 capacity_ = kInitialCapacity;
229 used_ = 0; 229 used_ = 0;
230 deleted_ = 0; 230 deleted_ = 0;
231 } 231 }
232 232
233 } // namespace dart 233 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698