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

Side by Side Diff: runtime/vm/dart_api_state.h

Issue 9368049: Add external byte array API and finalize external strings and byte arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 10 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 | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/gc_marker.cc » ('j') | 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) 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 #ifndef VM_DART_API_STATE_H_ 5 #ifndef VM_DART_API_STATE_H_
6 #define VM_DART_API_STATE_H_ 6 #define VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 class WeakPersistentHandle { 117 class WeakPersistentHandle {
118 public: 118 public:
119 // Accessors. 119 // Accessors.
120 RawObject* raw() const { return raw_; } 120 RawObject* raw() const { return raw_; }
121 void set_raw(RawObject* raw) { raw_ = raw; } 121 void set_raw(RawObject* raw) { raw_ = raw; }
122 void set_raw(const LocalHandle& ref) { raw_ = ref.raw(); } 122 void set_raw(const LocalHandle& ref) { raw_ = ref.raw(); }
123 void set_raw(const Object& object) { raw_ = object.raw(); } 123 void set_raw(const Object& object) { raw_ = object.raw(); }
124 static intptr_t raw_offset() { return OFFSET_OF(WeakPersistentHandle, raw_); } 124 static intptr_t raw_offset() { return OFFSET_OF(WeakPersistentHandle, raw_); }
125 void* peer() const { return peer_; } 125 void* peer() const { return peer_; }
126 void set_peer(void* peer) { peer_ = peer; } 126 void set_peer(void* peer) { peer_ = peer; }
127 Dart_PeerFinalizer callback() const { return callback_; } 127 Dart_WeakPersistentHandleFinalizer callback() const { return callback_; }
128 void set_callback(Dart_PeerFinalizer callback) { callback_ = callback; } 128 void set_callback(Dart_WeakPersistentHandleFinalizer callback) {
129 callback_ = callback;
130 }
129 131
130 void Finalize() { 132 static void Finalize(WeakPersistentHandle* handle) {
131 if (callback_ != NULL) { 133 if (handle->callback() != NULL) {
132 (*callback_)(peer_); 134 Dart_WeakPersistentHandleFinalizer callback = handle->callback();
135 void* peer = handle->peer();
136 handle->Clear();
137 (*callback)(reinterpret_cast<Dart_Handle>(handle), peer);
138 } else {
139 handle->Clear();
133 } 140 }
134 Clear();
135 } 141 }
136 142
137 private: 143 private:
138 friend class WeakPersistentHandles; 144 friend class WeakPersistentHandles;
139 145
140 WeakPersistentHandle() : raw_(NULL), peer_(NULL), callback_(NULL) { } 146 WeakPersistentHandle() : raw_(NULL), peer_(NULL), callback_(NULL) { }
141 ~WeakPersistentHandle() { } 147 ~WeakPersistentHandle() { }
142 148
143 // Overload the callback_ field as a next pointer when adding freed 149 // Overload the callback_ field as a next pointer when adding freed
144 // handles to the free list. 150 // handles to the free list.
145 WeakPersistentHandle* Next() { 151 WeakPersistentHandle* Next() {
146 return reinterpret_cast<WeakPersistentHandle*>(callback_); 152 return reinterpret_cast<WeakPersistentHandle*>(callback_);
147 } 153 }
148 void SetNext(WeakPersistentHandle* free_list) { 154 void SetNext(WeakPersistentHandle* free_list) {
149 callback_ = reinterpret_cast<Dart_PeerFinalizer>(free_list); 155 callback_ = reinterpret_cast<Dart_WeakPersistentHandleFinalizer>(free_list);
150 } 156 }
151 void FreeHandle(WeakPersistentHandle* free_list) { 157 void FreeHandle(WeakPersistentHandle* free_list) {
152 raw_ = NULL; 158 raw_ = NULL;
153 SetNext(free_list); 159 SetNext(free_list);
154 } 160 }
155 161
156 void Clear() { 162 void Clear() {
157 raw_ = Object::null(); 163 raw_ = Object::null();
158 peer_ = NULL; 164 peer_ = NULL;
159 callback_ = NULL; 165 callback_ = NULL;
160 } 166 }
161 167
162 RawObject* raw_; 168 RawObject* raw_;
163 void* peer_; 169 void* peer_;
164 Dart_PeerFinalizer callback_; 170 Dart_WeakPersistentHandleFinalizer callback_;
165 DISALLOW_ALLOCATION(); // Allocated through AllocateHandle methods. 171 DISALLOW_ALLOCATION(); // Allocated through AllocateHandle methods.
166 DISALLOW_COPY_AND_ASSIGN(WeakPersistentHandle); 172 DISALLOW_COPY_AND_ASSIGN(WeakPersistentHandle);
167 }; 173 };
168 174
169 175
170 // Local handles repository structure. 176 // Local handles repository structure.
171 static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize; 177 static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize;
172 static const int kLocalHandlesPerChunk = 64; 178 static const int kLocalHandlesPerChunk = 64;
173 static const int kOffsetOfRawPtrInLocalHandle = 0; 179 static const int kOffsetOfRawPtrInLocalHandle = 0;
174 class LocalHandles : Handles<kLocalHandleSizeInWords, 180 class LocalHandles : Handles<kLocalHandleSizeInWords,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 PersistentHandle* null_; 509 PersistentHandle* null_;
504 PersistentHandle* true_; 510 PersistentHandle* true_;
505 PersistentHandle* false_; 511 PersistentHandle* false_;
506 512
507 DISALLOW_COPY_AND_ASSIGN(ApiState); 513 DISALLOW_COPY_AND_ASSIGN(ApiState);
508 }; 514 };
509 515
510 } // namespace dart 516 } // namespace dart
511 517
512 #endif // VM_DART_API_STATE_H_ 518 #endif // VM_DART_API_STATE_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/gc_marker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698