| 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_
|
|
|