Index: runtime/vm/dart_api_impl.cc |
=================================================================== |
--- runtime/vm/dart_api_impl.cc (revision 3603) |
+++ runtime/vm/dart_api_impl.cc (working copy) |
@@ -15,8 +15,9 @@ |
#include "vm/exceptions.h" |
#include "vm/growable_array.h" |
#include "vm/longjump.h" |
-#include "vm/message_queue.h" |
+#include "vm/message.h" |
#include "vm/native_entry.h" |
+#include "vm/native_message_handler.h" |
#include "vm/object.h" |
#include "vm/object_store.h" |
#include "vm/port.h" |
@@ -676,7 +677,7 @@ |
Message::Priority priority = Message::kNormalPriority; |
do { |
DARTSCOPE(isolate); |
- message = isolate->message_queue()->DequeueNoWait(); |
+ message = isolate->message_handler()->queue()->DequeueNoWait(); |
if (message == NULL) { |
break; |
} |
@@ -705,7 +706,7 @@ |
DART_EXPORT bool Dart_HasLivePorts() { |
Isolate* isolate = Isolate::Current(); |
ASSERT(isolate); |
- return isolate->live_ports() > 0; |
+ return isolate->message_handler()->HasLivePorts(); |
} |
@@ -743,6 +744,41 @@ |
} |
+DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, |
+ Dart_NativeMessageHandler func, |
+ bool allow_concurrent) { |
+ if (name == NULL) { |
+ name = "<UnnamedNativePort>"; |
+ } |
+ if (func == NULL) { |
+ FATAL1("%s expects argument 'func' to be non-null.", CURRENT_FUNC); |
siva
2012/01/28 00:21:05
Why is this FATAL and not a
return Api::NewError(.
turnidge
2012/01/31 20:04:31
We can only do Api::NewError when we are in an iso
siva
2012/02/01 00:38:56
Agreed but it seems odd that a bad parameter resul
turnidge
2012/02/01 18:51:26
Ok. Done. Added a test for this too.
|
+ } |
+ // Start the native port without a current isolate. |
+ Isolate* saved = Isolate::Current(); |
Søren Gjesse
2012/01/27 13:33:14
How about a stack allocated isolate switcher?
{
turnidge
2012/01/31 20:04:31
I made an IsolateSaver class which handles the sav
|
+ Isolate::SetCurrent(NULL); |
siva
2012/01/28 00:21:05
Should we restrict creation of native ports only o
turnidge
2012/01/31 20:04:31
I'm not sure. I could see us often creating the n
siva
2012/02/01 00:38:56
Sure we can revisit this once we have usage patter
|
+ |
+ NativeMessageHandler* handler = new NativeMessageHandler(name, func); |
+ Dart_Port port_id = PortMap::CreatePort(handler); |
+ handler->StartWorker(); |
+ |
+ Isolate::SetCurrent(saved); |
+ return port_id; |
+} |
+ |
+ |
+DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) { |
+ // Close the native port without a current isolate. |
+ Isolate* saved = Isolate::Current(); |
+ Isolate::SetCurrent(NULL); |
siva
2012/01/28 00:21:05
Ditto regarding current isolate.
turnidge
2012/01/31 20:04:31
Maybe we can chat about it during the tea break.
|
+ |
+ // TODO(turnidge): Check that the port is native before trying to close. |
+ bool result = PortMap::ClosePort(native_port_id); |
+ |
+ Isolate::SetCurrent(saved); |
+ return result; |
+} |
+ |
+ |
DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
Isolate* isolate = Isolate::Current(); |
DARTSCOPE(isolate); |