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

Unified Diff: runtime/bin/file.cc

Issue 9569010: Use a pool of native ports for file 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/file.h ('k') | tests/standalone/src/ManyFileOperationsTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « runtime/bin/file.h ('k') | tests/standalone/src/ManyFileOperationsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698