| Index: runtime/vm/native_api_impl.cc
|
| diff --git a/runtime/vm/native_api_impl.cc b/runtime/vm/native_api_impl.cc
|
| index 9395bf3af891c97019babebab57d30c9ecf24b37..9d68624d9c422fdc1cfc03cb8e0a0b2a95376902 100644
|
| --- a/runtime/vm/native_api_impl.cc
|
| +++ b/runtime/vm/native_api_impl.cc
|
| @@ -22,6 +22,27 @@ static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
|
| }
|
|
|
|
|
| +class IsolateSaver {
|
| + public:
|
| + explicit IsolateSaver(Isolate* current_isolate)
|
| + : saved_isolate_(current_isolate) {
|
| + if (current_isolate != NULL) {
|
| + ASSERT(current_isolate == Isolate::Current());
|
| + Thread::ExitIsolate();
|
| + }
|
| + }
|
| + ~IsolateSaver() {
|
| + if (saved_isolate_ != NULL) {
|
| + Thread::EnterIsolate(saved_isolate_);
|
| + }
|
| + }
|
| + private:
|
| + Isolate* saved_isolate_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(IsolateSaver);
|
| +};
|
| +
|
| +
|
| DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) {
|
| uint8_t* buffer = NULL;
|
| ApiMessageWriter writer(&buffer, allocator);
|
| @@ -48,7 +69,6 @@ DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
|
| }
|
| // Start the native port without a current isolate.
|
| IsolateSaver saver(Isolate::Current());
|
| - Thread::ExitIsolate();
|
|
|
| NativeMessageHandler* nmh = new NativeMessageHandler(name, handler);
|
| Dart_Port port_id = PortMap::CreatePort(nmh);
|
| @@ -60,7 +80,6 @@ DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
|
| DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) {
|
| // Close the native port without a current isolate.
|
| IsolateSaver saver(Isolate::Current());
|
| - Thread::ExitIsolate();
|
|
|
| // TODO(turnidge): Check that the port is native before trying to close.
|
| return PortMap::ClosePort(native_port_id);
|
|
|