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

Unified Diff: runtime/bin/directory.cc

Issue 9568010: Use a pool of native ports for directory operations (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/directory.h ('k') | runtime/bin/directory_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory.cc
diff --git a/runtime/bin/directory.cc b/runtime/bin/directory.cc
index 31bbddbc86a22e5a8acfb26b0f5fe8ab9ce9fe9c..51397d394b9f891d4cd84d9c716f76d5658f7d6a 100644
--- a/runtime/bin/directory.cc
+++ b/runtime/bin/directory.cc
@@ -5,9 +5,15 @@
#include "bin/directory.h"
#include "bin/dartutils.h"
+#include "bin/thread.h"
#include "include/dart_api.h"
#include "platform/assert.h"
+dart::Mutex Directory::mutex_;
+int Directory::service_ports_size_ = 0;
+Dart_Port* Directory::service_ports_ = NULL;
+int Directory::service_ports_index_ = 0;
+
void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) {
static const int kError = -1;
static const int kExists = 1;
@@ -230,13 +236,35 @@ void DirectoryService(Dart_Port dest_port_id,
}
+Dart_Port Directory::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("DirectoryService",
+ DirectoryService,
+ 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(Directory_NewServicePort)(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_SetReturnValue(args, Dart_Null());
- Dart_Port service_port = kIllegalPort;
- service_port = Dart_NewNativePort("DirectoryService",
- DirectoryService,
- true);
+ Dart_Port service_port = Directory::GetServicePort();
if (service_port != kIllegalPort) {
// Return a send port for the service port.
Dart_Handle send_port = Dart_NewSendPort(service_port);
« no previous file with comments | « runtime/bin/directory.h ('k') | runtime/bin/directory_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698