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

Unified Diff: runtime/vm/dart_api_state.h

Issue 9325022: Decode the Dart message into a Dart_CMessage structure before calling the native port callback (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from asiva@ 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_message.cc ('k') | runtime/vm/growable_array.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 9badcc4fb9447228d1ad0ca6c148d081686b6f06..de4fd9947c313df6227759f21a6e46c151cac388 100644
--- a/runtime/vm/dart_api_state.h
+++ b/runtime/vm/dart_api_state.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -7,8 +7,10 @@
#include "include/dart_api.h"
+#include "platform/thread.h"
#include "vm/dart_api_impl.h"
#include "vm/flags.h"
+#include "vm/growable_array.h"
#include "vm/handles.h"
#include "vm/object.h"
#include "vm/os.h"
@@ -46,8 +48,11 @@ class ApiZone {
intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
private:
+ BaseZone* GetBaseZone() { return &zone_; }
+
BaseZone zone_;
+ template<typename T> friend class ApiGrowableArray;
DISALLOW_COPY_AND_ASSIGN(ApiZone);
};
@@ -507,6 +512,49 @@ class ApiState {
DISALLOW_COPY_AND_ASSIGN(ApiState);
};
+
+class ApiNativeScope {
+ public:
+ ApiNativeScope() {
+ // Currently no support for nesting native scopes.
+ ASSERT(Current() == NULL);
+ Thread::SetThreadLocal(Api::api_native_key_, reinterpret_cast<uword>(this));
+ }
+
+ ~ApiNativeScope() {
+ ASSERT(Current() == this);
+ Thread::SetThreadLocal(Api::api_native_key_, NULL);
+ }
+
+ static inline ApiNativeScope* Current() {
+ return reinterpret_cast<ApiNativeScope*>(
+ Thread::GetThreadLocal(Api::api_native_key_));
+ }
+
+ ApiZone* zone() { return &zone_; }
+
+ private:
+ ApiZone zone_;
+};
+
+
+// Api growable arrays use a zone for allocation. The constructor
+// picks the zone from the current isolate if in an isolate
+// environment. When outside an isolate environment it picks the zone
+// from the current native scope.
+template<typename T>
+class ApiGrowableArray : public BaseGrowableArray<T, ValueObject> {
+ public:
+ explicit ApiGrowableArray(int initial_capacity)
+ : BaseGrowableArray<T, ValueObject>(
+ initial_capacity,
+ ApiNativeScope::Current()->zone()->GetBaseZone()) {}
+ ApiGrowableArray()
+ : BaseGrowableArray<T, ValueObject>(
+ ApiNativeScope::Current()->zone()->GetBaseZone()) {}
+};
+
+
} // namespace dart
#endif // VM_DART_API_STATE_H_
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | runtime/vm/growable_array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698