| Index: runtime/bin/file.cc
|
| diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
|
| index 7cbf4db7f6dfec3934242118c844df6b48f86ea1..093ff4d4655fa7d49f9f64d5a08a1ac85e838c2c 100644
|
| --- a/runtime/bin/file.cc
|
| +++ b/runtime/bin/file.cc
|
| @@ -6,9 +6,14 @@
|
|
|
| #include "bin/builtin.h"
|
| #include "bin/dartutils.h"
|
| +#include "bin/thread.h"
|
|
|
| #include "include/dart_api.h"
|
|
|
| +dart::Mutex File::mutex_;
|
| +int File::service_ports_size_ = 0;
|
| +Dart_Port* File::service_ports_ = NULL;
|
| +int File::service_ports_index_ = 0;
|
|
|
| bool File::ReadFully(void* buffer, int64_t num_bytes) {
|
| int64_t remaining = num_bytes;
|
| @@ -725,13 +730,35 @@ void FileService(Dart_Port dest_port_id,
|
| }
|
|
|
|
|
| +Dart_Port File::GetServicePort() {
|
| + MutexLocker lock(&mutex_);
|
| + if (service_ports_size_ == 0) {
|
| + ASSERT(service_ports_ == NULL);
|
| + service_ports_size_ = 16;
|
| + service_ports_ = new Dart_Port[service_ports_size_];
|
| + service_ports_index_ = 0;
|
| + for (int i = 0; i < service_ports_size_; i++) {
|
| + service_ports_[i] = kIllegalPort;
|
| + }
|
| + }
|
| +
|
| + Dart_Port result = service_ports_[service_ports_index_];
|
| + if (result == kIllegalPort) {
|
| + result = Dart_NewNativePort("FileService",
|
| + FileService,
|
| + true);
|
| + ASSERT(result != kIllegalPort);
|
| + service_ports_[service_ports_index_] = result;
|
| + }
|
| + service_ports_index_ = (service_ports_index_ + 1) % service_ports_size_;
|
| + return result;
|
| +}
|
| +
|
| +
|
| void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) {
|
| Dart_EnterScope();
|
| Dart_SetReturnValue(args, Dart_Null());
|
| - Dart_Port service_port = kIllegalPort;
|
| - service_port = Dart_NewNativePort("FileService",
|
| - FileService,
|
| - true);
|
| + Dart_Port service_port = File::GetServicePort();
|
| if (service_port != kIllegalPort) {
|
| // Return a send port for the service port.
|
| Dart_Handle send_port = Dart_NewSendPort(service_port);
|
|
|