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

Side by Side Diff: vm/dart.cc

Issue 10450016: Add a callback to inform embedders when an isolate is being shut down. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/dart.h ('k') | vm/dart_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/dart.h" 5 #include "vm/dart.h"
6 6
7 #include "vm/dart_api_state.h" 7 #include "vm/dart_api_state.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/freelist.h" 9 #include "vm/freelist.h"
10 #include "vm/handles.h" 10 #include "vm/handles.h"
(...skipping 12 matching lines...) Expand all
23 23
24 DECLARE_FLAG(bool, print_class_table); 24 DECLARE_FLAG(bool, print_class_table);
25 DECLARE_FLAG(bool, trace_isolates); 25 DECLARE_FLAG(bool, trace_isolates);
26 26
27 Isolate* Dart::vm_isolate_ = NULL; 27 Isolate* Dart::vm_isolate_ = NULL;
28 ThreadPool* Dart::thread_pool_ = NULL; 28 ThreadPool* Dart::thread_pool_ = NULL;
29 DebugInfo* Dart::pprof_symbol_generator_ = NULL; 29 DebugInfo* Dart::pprof_symbol_generator_ = NULL;
30 30
31 // TODO(turnidge): We should add a corresponding Dart::Cleanup. 31 // TODO(turnidge): We should add a corresponding Dart::Cleanup.
32 bool Dart::InitOnce(Dart_IsolateCreateCallback create, 32 bool Dart::InitOnce(Dart_IsolateCreateCallback create,
33 Dart_IsolateInterruptCallback interrupt) { 33 Dart_IsolateInterruptCallback interrupt,
34 Dart_IsolateShutdownCallback shutdown) {
34 // TODO(iposva): Fix race condition here. 35 // TODO(iposva): Fix race condition here.
35 if (vm_isolate_ != NULL || !Flags::Initialized()) { 36 if (vm_isolate_ != NULL || !Flags::Initialized()) {
36 return false; 37 return false;
37 } 38 }
38 OS::InitOnce(); 39 OS::InitOnce();
39 VirtualMemory::InitOnce(); 40 VirtualMemory::InitOnce();
40 Isolate::InitOnce(); 41 Isolate::InitOnce();
41 PortMap::InitOnce(); 42 PortMap::InitOnce();
42 FreeListElement::InitOnce(); 43 FreeListElement::InitOnce();
43 Api::InitOnce(); 44 Api::InitOnce();
44 // Create the VM isolate and finish the VM initialization. 45 // Create the VM isolate and finish the VM initialization.
45 ASSERT(thread_pool_ == NULL); 46 ASSERT(thread_pool_ == NULL);
46 thread_pool_ = new ThreadPool(); 47 thread_pool_ = new ThreadPool();
47 { 48 {
48 ASSERT(vm_isolate_ == NULL); 49 ASSERT(vm_isolate_ == NULL);
49 ASSERT(Flags::Initialized()); 50 ASSERT(Flags::Initialized());
50 vm_isolate_ = Isolate::Init("vm-isolate"); 51 vm_isolate_ = Isolate::Init("vm-isolate");
51 Zone zone(vm_isolate_); 52 Zone zone(vm_isolate_);
52 HandleScope handle_scope(vm_isolate_); 53 HandleScope handle_scope(vm_isolate_);
53 Heap::Init(vm_isolate_); 54 Heap::Init(vm_isolate_);
54 ObjectStore::Init(vm_isolate_); 55 ObjectStore::Init(vm_isolate_);
55 Object::InitOnce(); 56 Object::InitOnce();
56 StubCode::InitOnce(); 57 StubCode::InitOnce();
57 Scanner::InitOnce(); 58 Scanner::InitOnce();
58 } 59 }
59 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread. 60 Isolate::SetCurrent(NULL); // Unregister the VM isolate from this thread.
60 Isolate::SetCreateCallback(create); 61 Isolate::SetCreateCallback(create);
61 Isolate::SetInterruptCallback(interrupt); 62 Isolate::SetInterruptCallback(interrupt);
63 Isolate::SetShutdownCallback(shutdown);
62 return true; 64 return true;
63 } 65 }
64 66
65 67
66 Isolate* Dart::CreateIsolate(const char* name_prefix) { 68 Isolate* Dart::CreateIsolate(const char* name_prefix) {
67 // Create a new isolate. 69 // Create a new isolate.
68 Isolate* isolate = Isolate::Init(name_prefix); 70 Isolate* isolate = Isolate::Init(name_prefix);
69 ASSERT(isolate != NULL); 71 ASSERT(isolate != NULL);
70 return isolate; 72 return isolate;
71 } 73 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 isolate->set_init_callback_data(data); 107 isolate->set_init_callback_data(data);
106 if (FLAG_print_class_table) { 108 if (FLAG_print_class_table) {
107 isolate->class_table()->Print(); 109 isolate->class_table()->Print();
108 } 110 }
109 return Error::null(); 111 return Error::null();
110 } 112 }
111 113
112 114
113 void Dart::ShutdownIsolate() { 115 void Dart::ShutdownIsolate() {
114 Isolate* isolate = Isolate::Current(); 116 Isolate* isolate = Isolate::Current();
117 void* callback_data = isolate->init_callback_data();
115 isolate->Shutdown(); 118 isolate->Shutdown();
116 delete isolate; 119 delete isolate;
120
121 Dart_IsolateShutdownCallback callback = Isolate::ShutdownCallback();
122 if (callback != NULL) {
123 (callback)(callback_data);
124 }
117 } 125 }
118 126
119 } // namespace dart 127 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart.h ('k') | vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698