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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/gc_marker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f039db0a2ec002ee97e07cf72c473d561fa1e482 100644
--- a/runtime/vm/dart_api_state.h
+++ b/runtime/vm/dart_api_state.h
@@ -348,6 +348,59 @@ 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() const { return next_; }
+
+ intptr_t num_keys() const { 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() const { 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) {
+ ASSERT(queue != NULL);
+ WeakReference* head = *queue;
+ if (head != NULL) {
+ *queue = head->next();
+ head->next_ = NULL;
+ }
+ return head;
+ }
+
+ static void Push(WeakReference* reference, WeakReference** queue) {
+ ASSERT(reference != NULL);
+ ASSERT(queue != NULL);
+ reference->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 +433,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 +462,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 +563,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_;
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/gc_marker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698