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

Unified Diff: runtime/vm/dart_api_state.h

Issue 9531001: Implement weak references sets and provide an embedding API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minor changes to prepare for review 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_state.h
diff --git a/runtime/vm/dart_api_state.h b/runtime/vm/dart_api_state.h
index 359dde6b846ca33d307e09067457102aa982c7fe..fe72901ac45d69d7ed30483173a8bdae01d0a3cd 100644
--- a/runtime/vm/dart_api_state.h
+++ b/runtime/vm/dart_api_state.h
@@ -348,6 +348,57 @@ class WeakPersistentHandles : Handles<kWeakPersistentHandleSizeInWords,
};
+class WeakReference {
+ public:
+ WeakReference(Dart_Handle* keys, intptr_t keys_length,
+ Dart_Handle* values, intptr_t values_length)
+ : next_(NULL),
+ keys_(keys), num_keys_(keys_length),
+ values_(values), num_values_(values_length) {
+ }
+ ~WeakReference() {}
+
+ WeakReference* next() { return next_; }
siva 2012/03/02 18:30:33 next() const { ... } Ditto comment for other acce
cshapiro 2012/03/03 00:03:23 Right. Done.
+ void set_next(WeakReference* next) { next_ = next; }
siva 2012/03/02 18:30:33 Do next and set_next have to be part of the public
cshapiro 2012/03/03 00:03:23 Done. In fact, I added this method before I had P
+
+ intptr_t num_keys() { return num_keys_; }
+ RawObject** get_key(intptr_t i) {
+ ASSERT(i >= 0);
+ ASSERT(i < num_keys_);
+ return reinterpret_cast<RawObject**>(keys_[i]);
+ }
+
+ intptr_t num_values() { return num_values_; }
+ RawObject** get_value(intptr_t i) {
+ ASSERT(i >= 0);
+ ASSERT(i < num_values_);
+ return reinterpret_cast<RawObject**>(values_[i]);
+ }
+
+ static WeakReference* Pop(WeakReference** queue) {
siva 2012/03/02 18:30:33 ASSERT(queue != NULL);
cshapiro 2012/03/03 00:03:23 Done.
+ WeakReference* head = *queue;
+ if (head != NULL) {
+ *queue = head->next();
+ head->set_next(NULL);
+ }
+ return head;
+ }
+
+ static void Push(WeakReference* reference, WeakReference** queue) {
siva 2012/03/02 18:30:33 ASSERT(queue != NULL); ASSERT(reference != NULL);
cshapiro 2012/03/03 00:03:23 Also done. Thanks!
+ reference->set_next(*queue);
+ *queue = reference;
+ }
+
+ private:
+ WeakReference* next_;
+ Dart_Handle* keys_;
+ intptr_t num_keys_;
+ Dart_Handle* values_;
+ intptr_t num_values_;
+ DISALLOW_COPY_AND_ASSIGN(WeakReference);
+};
+
+
// Structure used for the implementation of local scopes used in dart_api.
// These local scopes manage handles and memory allocated in the scope.
class ApiLocalScope {
@@ -380,7 +431,8 @@ class ApiLocalScope {
// basis and destroyed when the isolate is shutdown.
class ApiState {
public:
- ApiState() : top_scope_(NULL), null_(NULL), true_(NULL), false_(NULL) { }
+ ApiState() : top_scope_(NULL), delayed_weak_references_(NULL),
+ null_(NULL), true_(NULL), false_(NULL) { }
~ApiState() {
while (top_scope_ != NULL) {
ApiLocalScope* scope = top_scope_;
@@ -408,7 +460,10 @@ class ApiState {
WeakPersistentHandles& weak_persistent_handles() {
return weak_persistent_handles_;
}
-
+ WeakReference* delayed_weak_references() { return delayed_weak_references_; }
+ void set_delayed_weak_references(WeakReference* reference) {
+ delayed_weak_references_ = reference;
+ }
void UnwindScopes(uword sp) {
while (top_scope_ != NULL && top_scope_->stack_marker() < sp) {
ApiLocalScope* scope = top_scope_;
@@ -506,10 +561,15 @@ class ApiState {
return false_;
}
+ void DelayWeakReference(WeakReference* reference) {
+ WeakReference::Push(reference, &delayed_weak_references_);
+ }
+
private:
PersistentHandles persistent_handles_;
WeakPersistentHandles weak_persistent_handles_;
ApiLocalScope* top_scope_;
+ WeakReference* delayed_weak_references_;
// Persistent handles to important objects.
PersistentHandle* null_;

Powered by Google App Engine
This is Rietveld 408576698