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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 9924015: Use the ThreadPool for all isolates and native ports. Previously, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 Dart_MessageNotifyCallback message_notify_callback) { 764 Dart_MessageNotifyCallback message_notify_callback) {
765 Isolate* isolate = Isolate::Current(); 765 Isolate* isolate = Isolate::Current();
766 CHECK_ISOLATE(isolate); 766 CHECK_ISOLATE(isolate);
767 isolate->set_message_notify_callback(message_notify_callback); 767 isolate->set_message_notify_callback(message_notify_callback);
768 } 768 }
769 769
770 770
771 DART_EXPORT Dart_Handle Dart_RunLoop() { 771 DART_EXPORT Dart_Handle Dart_RunLoop() {
772 Isolate* isolate = Isolate::Current(); 772 Isolate* isolate = Isolate::Current();
773 DARTSCOPE(isolate); 773 DARTSCOPE(isolate);
774 const Object& obj = Object::Handle(isolate, isolate->StandardRunLoop()); 774 {
775 SetIsolateScope set_scope(NULL);
siva 2012/04/14 00:29:53 Why is NULL passed in and not isolate? Won't it en
turnidge 2012/04/17 23:46:55 Yeah. When I call RunBlocking, it actually runs t
turnidge 2012/04/17 23:49:21 These comments are out of date, now that I've remo
776 isolate->message_handler()->RunBlocking(Dart::thread_pool(), NULL, NULL);
777 }
778 const Object& obj = Object::Handle(isolate->object_store()->sticky_error());
779 isolate->object_store()->clear_sticky_error();
775 if (obj.IsError()) { 780 if (obj.IsError()) {
776 return Api::NewHandle(isolate, obj.raw()); 781 return Api::NewHandle(isolate, obj.raw());
777 } 782 }
778 ASSERT(obj.IsNull()); 783 ASSERT(obj.IsNull());
779 return Api::Success(isolate); 784 return Api::Success(isolate);
780 } 785 }
781 786
782 787
783 static RawInstance* DeserializeMessage(Isolate* isolate, void* data) {
784 // Create a snapshot object using the buffer.
785 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
786 ASSERT(snapshot->IsMessageSnapshot());
787
788 // Read object back from the snapshot.
789 SnapshotReader reader(snapshot, isolate);
790 Instance& instance = Instance::Handle(isolate);
791 instance ^= reader.ReadObject();
792 return instance.raw();
793 }
794
795
796 DART_EXPORT Dart_Handle Dart_HandleMessage() { 788 DART_EXPORT Dart_Handle Dart_HandleMessage() {
797 Isolate* isolate = Isolate::Current(); 789 Isolate* isolate = Isolate::Current();
798 // Process all OOB messages and at most one normal message. 790 CHECK_ISOLATE(isolate);
799 Message* message = NULL; 791 if (!isolate->message_handler()->HandleNextMessage()) {
800 Message::Priority priority = Message::kNormalPriority; 792 // TODO(turnidge): Clear sticky error here?
801 do { 793 return Api::NewHandle(isolate, isolate->object_store()->sticky_error());
802 DARTSCOPE(isolate); 794 }
803 // TODO(turnidge): This code is duplicated elsewhere. Consolidate.
804 message = isolate->message_handler()->queue()->DequeueNoWait();
805 if (message == NULL) {
806 break;
807 }
808 const Instance& msg =
809 Instance::Handle(isolate, DeserializeMessage(isolate, message->data()));
810 priority = message->priority();
811 if (priority == Message::kOOBPriority) {
812 // For now the only OOB messages are Mirrors messages.
813 const Object& result = Object::Handle(
814 isolate,
815 DartLibraryCalls::HandleMirrorsMessage(
816 message->dest_port(), message->reply_port(), msg));
817 delete message;
818 if (result.IsError()) {
819 // TODO(turnidge): Propagating the error is probably wrong here.
820 return Api::NewHandle(isolate, result.raw());
821 }
822 ASSERT(result.IsNull());
823 } else {
824 const Object& result = Object::Handle(
825 isolate,
826 DartLibraryCalls::HandleMessage(
827 message->dest_port(), message->reply_port(), msg));
828 delete message;
829 if (result.IsError()) {
830 return Api::NewHandle(isolate, result.raw());
831 }
832 ASSERT(result.IsNull());
833 }
834 } while (priority >= Message::kOOBPriority);
835 return Api::Success(isolate); 795 return Api::Success(isolate);
836 } 796 }
837 797
838 798
839 DART_EXPORT bool Dart_HasLivePorts() { 799 DART_EXPORT bool Dart_HasLivePorts() {
840 Isolate* isolate = Isolate::Current(); 800 Isolate* isolate = Isolate::Current();
841 ASSERT(isolate); 801 ASSERT(isolate);
842 return isolate->message_handler()->HasLivePorts(); 802 return isolate->message_handler()->HasLivePorts();
843 } 803 }
844 804
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 if (handler == NULL) { 858 if (handler == NULL) {
899 OS::PrintErr("%s expects argument 'handler' to be non-null.", CURRENT_FUNC); 859 OS::PrintErr("%s expects argument 'handler' to be non-null.", CURRENT_FUNC);
900 return kIllegalPort; 860 return kIllegalPort;
901 } 861 }
902 // Start the native port without a current isolate. 862 // Start the native port without a current isolate.
903 IsolateSaver saver(Isolate::Current()); 863 IsolateSaver saver(Isolate::Current());
904 Isolate::SetCurrent(NULL); 864 Isolate::SetCurrent(NULL);
905 865
906 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler); 866 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler);
907 Dart_Port port_id = PortMap::CreatePort(nmh); 867 Dart_Port port_id = PortMap::CreatePort(nmh);
908 nmh->StartWorker(); 868 nmh->Run(Dart::thread_pool(), NULL, NULL);
909 return port_id; 869 return port_id;
910 } 870 }
911 871
912 872
913 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) { 873 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) {
914 // Close the native port without a current isolate. 874 // Close the native port without a current isolate.
915 IsolateSaver saver(Isolate::Current()); 875 IsolateSaver saver(Isolate::Current());
916 Isolate::SetCurrent(NULL); 876 Isolate::SetCurrent(NULL);
917 877
918 // TODO(turnidge): Check that the port is native before trying to close. 878 // TODO(turnidge): Check that the port is native before trying to close.
(...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 *buffer = NULL; 3359 *buffer = NULL;
3400 } 3360 }
3401 delete debug_region; 3361 delete debug_region;
3402 } else { 3362 } else {
3403 *buffer = NULL; 3363 *buffer = NULL;
3404 *buffer_size = 0; 3364 *buffer_size = 0;
3405 } 3365 }
3406 } 3366 }
3407 3367
3408 } // namespace dart 3368 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698