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

Unified Diff: runtime/vm/native_api_impl.cc

Issue 1439483003: - Add an OSThread structure which is the generic TLS structure for all C++ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review Created 5 years, 1 month 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/message_handler_test.cc ('k') | runtime/vm/os_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/os_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698