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

Side by Side Diff: runtime/bin/file.cc

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 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/bin/file.h ('k') | runtime/bin/platform_win.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "bin/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/io_buffer.h" 9 #include "bin/io_buffer.h"
10 #include "bin/thread.h" 10 #include "bin/thread.h"
11 #include "bin/utils.h" 11 #include "bin/utils.h"
12 12
13 #include "include/dart_api.h" 13 #include "include/dart_api.h"
14 14
15 static const int kMSPerSecond = 1000; 15 static const int kMSPerSecond = 1000;
16 16
17 dart::Mutex File::mutex_; 17
18 int File::service_ports_size_ = 0; 18 // Forward declaration.
19 Dart_Port* File::service_ports_ = NULL; 19 static void FileService(Dart_Port, Dart_Port, Dart_CObject*);
20 int File::service_ports_index_ = 0; 20
21 NativeService File::file_service_("FileService", FileService, 16);
21 22
22 23
23 // The file pointer has been passed into Dart as an intptr_t and it is safe 24 // The file pointer has been passed into Dart as an intptr_t and it is safe
24 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and 25 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and
25 // from there to a File pointer. 26 // from there to a File pointer.
26 static File* GetFilePointer(Dart_Handle handle) { 27 static File* GetFilePointer(Dart_Handle handle) {
27 intptr_t value = DartUtils::GetIntptrValue(handle); 28 intptr_t value = DartUtils::GetIntptrValue(handle);
28 return reinterpret_cast<File*>(value); 29 return reinterpret_cast<File*>(value);
29 } 30 }
30 31
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 return CObject::NewOSError(); 884 return CObject::NewOSError();
884 } 885 }
885 } else { 886 } else {
886 return CObject::FileClosedError(); 887 return CObject::FileClosedError();
887 } 888 }
888 } 889 }
889 return CObject::IllegalArgumentError(); 890 return CObject::IllegalArgumentError();
890 } 891 }
891 892
892 893
893 void FileService(Dart_Port dest_port_id, 894 static void FileService(Dart_Port dest_port_id,
894 Dart_Port reply_port_id, 895 Dart_Port reply_port_id,
895 Dart_CObject* message) { 896 Dart_CObject* message) {
896 CObject* response = CObject::False(); 897 CObject* response = CObject::IllegalArgumentError();
897 CObjectArray request(message); 898 CObjectArray request(message);
898 if (message->type == Dart_CObject::kArray) { 899 if (message->type == Dart_CObject::kArray) {
899 if (request.Length() > 1 && request[0]->IsInt32()) { 900 if (request.Length() > 1 && request[0]->IsInt32()) {
900 CObjectInt32 requestType(request[0]); 901 CObjectInt32 requestType(request[0]);
901 switch (requestType.Value()) { 902 switch (requestType.Value()) {
902 case File::kExistsRequest: 903 case File::kExistsRequest:
903 response = FileExistsRequest(request); 904 response = FileExistsRequest(request);
904 break; 905 break;
905 case File::kCreateRequest: 906 case File::kCreateRequest:
906 response = FileCreateRequest(request); 907 response = FileCreateRequest(request);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 UNREACHABLE(); 961 UNREACHABLE();
961 } 962 }
962 } 963 }
963 } 964 }
964 965
965 Dart_PostCObject(reply_port_id, response->AsApiCObject()); 966 Dart_PostCObject(reply_port_id, response->AsApiCObject());
966 } 967 }
967 968
968 969
969 Dart_Port File::GetServicePort() { 970 Dart_Port File::GetServicePort() {
970 MutexLocker lock(&mutex_); 971 return file_service_.GetServicePort();
971 if (service_ports_size_ == 0) {
972 ASSERT(service_ports_ == NULL);
973 service_ports_size_ = 16;
974 service_ports_ = new Dart_Port[service_ports_size_];
975 service_ports_index_ = 0;
976 for (int i = 0; i < service_ports_size_; i++) {
977 service_ports_[i] = ILLEGAL_PORT;
978 }
979 }
980
981 Dart_Port result = service_ports_[service_ports_index_];
982 if (result == ILLEGAL_PORT) {
983 result = Dart_NewNativePort("FileService",
984 FileService,
985 true);
986 ASSERT(result != ILLEGAL_PORT);
987 service_ports_[service_ports_index_] = result;
988 }
989 service_ports_index_ = (service_ports_index_ + 1) % service_ports_size_;
990 return result;
991 } 972 }
992 973
993 974
994 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) { 975 void FUNCTION_NAME(File_NewServicePort)(Dart_NativeArguments args) {
995 Dart_EnterScope(); 976 Dart_EnterScope();
996 Dart_SetReturnValue(args, Dart_Null()); 977 Dart_SetReturnValue(args, Dart_Null());
997 Dart_Port service_port = File::GetServicePort(); 978 Dart_Port service_port = File::GetServicePort();
998 if (service_port != ILLEGAL_PORT) { 979 if (service_port != ILLEGAL_PORT) {
999 // Return a send port for the service port. 980 // Return a send port for the service port.
1000 Dart_Handle send_port = Dart_NewSendPort(service_port); 981 Dart_Handle send_port = Dart_NewSendPort(service_port);
1001 Dart_SetReturnValue(args, send_port); 982 Dart_SetReturnValue(args, send_port);
1002 } 983 }
1003 Dart_ExitScope(); 984 Dart_ExitScope();
1004 } 985 }
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/platform_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698