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

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

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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"
11 #include "vm/dart_api_impl.h" 11 #include "vm/dart_api_impl.h"
12 #include "vm/dart_api_state.h" 12 #include "vm/dart_api_state.h"
13 #include "vm/dart_entry.h" 13 #include "vm/dart_entry.h"
14 #include "vm/debuginfo.h" 14 #include "vm/debuginfo.h"
15 #include "vm/exceptions.h" 15 #include "vm/exceptions.h"
16 #include "vm/growable_array.h" 16 #include "vm/growable_array.h"
17 #include "vm/longjump.h" 17 #include "vm/longjump.h"
18 #include "vm/message_queue.h" 18 #include "vm/message.h"
19 #include "vm/native_entry.h" 19 #include "vm/native_entry.h"
20 #include "vm/native_message_handler.h"
20 #include "vm/object.h" 21 #include "vm/object.h"
21 #include "vm/object_store.h" 22 #include "vm/object_store.h"
22 #include "vm/port.h" 23 #include "vm/port.h"
23 #include "vm/resolver.h" 24 #include "vm/resolver.h"
24 #include "vm/snapshot.h" 25 #include "vm/snapshot.h"
25 #include "vm/stack_frame.h" 26 #include "vm/stack_frame.h"
26 #include "vm/timer.h" 27 #include "vm/timer.h"
27 #include "vm/verifier.h" 28 #include "vm/verifier.h"
28 29
29 namespace dart { 30 namespace dart {
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 670 }
670 671
671 672
672 DART_EXPORT Dart_Handle Dart_HandleMessage() { 673 DART_EXPORT Dart_Handle Dart_HandleMessage() {
673 Isolate* isolate = Isolate::Current(); 674 Isolate* isolate = Isolate::Current();
674 // Process all OOB messages and at most one normal message. 675 // Process all OOB messages and at most one normal message.
675 Message* message = NULL; 676 Message* message = NULL;
676 Message::Priority priority = Message::kNormalPriority; 677 Message::Priority priority = Message::kNormalPriority;
677 do { 678 do {
678 DARTSCOPE(isolate); 679 DARTSCOPE(isolate);
679 message = isolate->message_queue()->DequeueNoWait(); 680 message = isolate->message_handler()->queue()->DequeueNoWait();
680 if (message == NULL) { 681 if (message == NULL) {
681 break; 682 break;
682 } 683 }
683 priority = message->priority(); 684 priority = message->priority();
684 if (priority == Message::kOOBPriority) { 685 if (priority == Message::kOOBPriority) {
685 // TODO(turnidge): Out of band messages will not go through the 686 // TODO(turnidge): Out of band messages will not go through the
686 // regular message handler. Instead they will be dispatched to 687 // regular message handler. Instead they will be dispatched to
687 // special vm code. Implement. 688 // special vm code. Implement.
688 UNIMPLEMENTED(); 689 UNIMPLEMENTED();
689 } 690 }
690 const Instance& msg = 691 const Instance& msg =
691 Instance::Handle(DeserializeMessage(message->data())); 692 Instance::Handle(DeserializeMessage(message->data()));
692 const Object& result = Object::Handle( 693 const Object& result = Object::Handle(
693 DartLibraryCalls::HandleMessage( 694 DartLibraryCalls::HandleMessage(
694 message->dest_port(), message->reply_port(), msg)); 695 message->dest_port(), message->reply_port(), msg));
695 delete message; 696 delete message;
696 if (result.IsError()) { 697 if (result.IsError()) {
697 return Api::NewLocalHandle(result); 698 return Api::NewLocalHandle(result);
698 } 699 }
699 ASSERT(result.IsNull()); 700 ASSERT(result.IsNull());
700 } while (priority >= Message::kOOBPriority); 701 } while (priority >= Message::kOOBPriority);
701 return Api::Success(); 702 return Api::Success();
702 } 703 }
703 704
704 705
705 DART_EXPORT bool Dart_HasLivePorts() { 706 DART_EXPORT bool Dart_HasLivePorts() {
706 Isolate* isolate = Isolate::Current(); 707 Isolate* isolate = Isolate::Current();
707 ASSERT(isolate); 708 ASSERT(isolate);
708 return isolate->live_ports() > 0; 709 return isolate->message_handler()->HasLivePorts();
709 } 710 }
710 711
711 712
712 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 713 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
713 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 714 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
714 return reinterpret_cast<uint8_t*>(new_ptr); 715 return reinterpret_cast<uint8_t*>(new_ptr);
715 } 716 }
716 717
717 718
718 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, 719 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id,
(...skipping 17 matching lines...) Expand all
736 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); 737 const Object& object = Object::Handle(Api::UnwrapHandle(handle));
737 uint8_t* data = NULL; 738 uint8_t* data = NULL;
738 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); 739 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator);
739 writer.WriteObject(object.raw()); 740 writer.WriteObject(object.raw());
740 writer.FinalizeBuffer(); 741 writer.FinalizeBuffer();
741 return PortMap::PostMessage(new Message( 742 return PortMap::PostMessage(new Message(
742 port_id, Message::kIllegalPort, data, Message::kNormalPriority)); 743 port_id, Message::kIllegalPort, data, Message::kNormalPriority));
743 } 744 }
744 745
745 746
747 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
748 Dart_NativeMessageHandler handler,
749 bool handle_concurrently) {
750 if (name == NULL) {
751 name = "<UnnamedNativePort>";
752 }
753 if (handler == NULL) {
754 OS::PrintErr("%s expects argument 'handler' to be non-null.", CURRENT_FUNC);
755 return kIllegalPort;
756 }
757 // Start the native port without a current isolate.
758 IsolateSaver saver(Isolate::Current());
759 Isolate::SetCurrent(NULL);
760
761 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler);
762 Dart_Port port_id = PortMap::CreatePort(nmh);
763 nmh->StartWorker();
764 return port_id;
765 }
766
767
768 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) {
769 // Close the native port without a current isolate.
770 IsolateSaver saver(Isolate::Current());
771 Isolate::SetCurrent(NULL);
772
773 // TODO(turnidge): Check that the port is native before trying to close.
774 return PortMap::ClosePort(native_port_id);
775 }
776
777
746 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { 778 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) {
747 Isolate* isolate = Isolate::Current(); 779 Isolate* isolate = Isolate::Current();
748 DARTSCOPE(isolate); 780 DARTSCOPE(isolate);
749 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); 781 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl"));
750 const String& function_name = String::Handle(String::NewSymbol("_create")); 782 const String& function_name = String::Handle(String::NewSymbol("_create"));
751 const int kNumArguments = 1; 783 const int kNumArguments = 1;
752 const Array& kNoArgumentNames = Array::Handle(); 784 const Array& kNoArgumentNames = Array::Handle();
753 // TODO(turnidge): Consider adding a helper function to make 785 // TODO(turnidge): Consider adding a helper function to make
754 // function resolution by class name and function name more concise. 786 // function resolution by class name and function name more concise.
755 const Function& function = Function::Handle( 787 const Function& function = Function::Handle(
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 } 2524 }
2493 delete debug_region; 2525 delete debug_region;
2494 } else { 2526 } else {
2495 *buffer = NULL; 2527 *buffer = NULL;
2496 *buffer_size = 0; 2528 *buffer_size = 0;
2497 } 2529 }
2498 } 2530 }
2499 2531
2500 2532
2501 } // namespace dart 2533 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698