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

Unified Diff: runtime/bin/file.cc

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | « no previous file | runtime/bin/process.cc » ('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 f0205fb8b5275af344212bbdd5feae9787cf7353..aab021bc1f4da2b3da60618049d960b2b69db35a 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -11,6 +11,7 @@
#include "bin/utils.h"
#include "include/dart_api.h"
+#include "include/dart_native_api.h"
namespace dart {
namespace bin {
@@ -30,14 +31,17 @@ static File* GetFilePointer(Dart_Handle handle) {
bool File::ReadFully(void* buffer, int64_t num_bytes) {
int64_t remaining = num_bytes;
char* current_buffer = reinterpret_cast<char*>(buffer);
+ Dart_DisableThreadInterrupter();
siva 2013/12/13 21:29:14 I am wondering if we should have a macro around al
Cutch 2013/12/13 22:40:18 I'm not sure how to build a macro like that in a p
while (remaining > 0) {
int bytes_read = Read(current_buffer, remaining);
if (bytes_read <= 0) {
+ Dart_EnableThreadInterrupter();
return false;
}
remaining -= bytes_read; // Reduce the number of remaining bytes.
current_buffer += bytes_read; // Move the buffer forward.
}
+ Dart_EnableThreadInterrupter();
return true;
}
@@ -45,14 +49,17 @@ bool File::ReadFully(void* buffer, int64_t num_bytes) {
bool File::WriteFully(const void* buffer, int64_t num_bytes) {
int64_t remaining = num_bytes;
const char* current_buffer = reinterpret_cast<const char*>(buffer);
+ Dart_DisableThreadInterrupter();
while (remaining > 0) {
int bytes_read = Write(current_buffer, remaining);
if (bytes_read < 0) {
+ Dart_EnableThreadInterrupter();
return false;
}
remaining -= bytes_read; // Reduce the number of remaining bytes.
current_buffer += bytes_read; // Move the buffer forward.
}
+ Dart_EnableThreadInterrupter();
return true;
}
@@ -115,7 +122,9 @@ void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) {
File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
ASSERT(file != NULL);
uint8_t buffer;
+ Dart_DisableThreadInterrupter();
int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1);
+ Dart_EnableThreadInterrupter();
if (bytes_read == 1) {
Dart_SetReturnValue(args, Dart_NewInteger(buffer));
} else if (bytes_read == 0) {
@@ -134,7 +143,9 @@ void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) {
int64_t byte = 0;
if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &byte)) {
uint8_t buffer = static_cast<uint8_t>(byte & 0xff);
+ Dart_DisableThreadInterrupter();
int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1);
+ Dart_EnableThreadInterrupter();
if (bytes_written >= 0) {
Dart_SetReturnValue(args, Dart_NewInteger(bytes_written));
} else {
@@ -159,7 +170,9 @@ void FUNCTION_NAME(File_Read)(Dart_NativeArguments args) {
if (DartUtils::GetInt64Value(length_object, &length)) {
uint8_t* buffer = NULL;
Dart_Handle external_array = IOBuffer::Allocate(length, &buffer);
+ Dart_DisableThreadInterrupter();
int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length);
+ Dart_EnableThreadInterrupter();
if (bytes_read < 0) {
Dart_Handle err = DartUtils::NewDartOSError();
if (Dart_IsError(err)) Dart_PropagateError(err);
@@ -214,7 +227,9 @@ void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) {
if (Dart_IsError(result)) Dart_PropagateError(result);
ASSERT(end <= array_len);
uint8_t* buffer = new uint8_t[length];
+ Dart_DisableThreadInterrupter();
int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length);
+ Dart_EnableThreadInterrupter();
if (bytes_read >= 0) {
result = Dart_ListSetAsBytes(buffer_obj, start, buffer, bytes_read);
if (Dart_IsError(result)) {
@@ -261,8 +276,9 @@ void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) {
ASSERT(buffer != NULL);
// Write the data out into the file.
+ Dart_DisableThreadInterrupter();
int64_t bytes_written = file->Write(reinterpret_cast<void*>(buffer), length);
-
+ Dart_EnableThreadInterrupter();
// Release the direct pointer acquired above.
result = Dart_TypedDataReleaseData(buffer_obj);
if (Dart_IsError(result)) Dart_PropagateError(result);
@@ -866,7 +882,9 @@ CObject* File::ReadByteRequest(const CObjectArray& request) {
ASSERT(file != NULL);
if (!file->IsClosed()) {
uint8_t buffer;
+ Dart_DisableThreadInterrupter();
int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1);
+ Dart_EnableThreadInterrupter();
if (bytes_read > 0) {
return new CObjectIntptr(CObject::NewIntptr(buffer));
} else if (bytes_read == 0) {
@@ -891,7 +909,9 @@ CObject* File::WriteByteRequest(const CObjectArray& request) {
if (!file->IsClosed()) {
int64_t byte = CObjectInt32OrInt64ToInt64(request[1]);
uint8_t buffer = static_cast<uint8_t>(byte & 0xff);
+ Dart_DisableThreadInterrupter();
int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1);
+ Dart_EnableThreadInterrupter();
if (bytes_written > 0) {
return new CObjectInt64(CObject::NewInt64(bytes_written));
} else {
@@ -916,7 +936,9 @@ CObject* File::ReadRequest(const CObjectArray& request) {
Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
ASSERT(io_buffer != NULL);
uint8_t* data = io_buffer->value.as_external_typed_data.data;
+ Dart_DisableThreadInterrupter();
int64_t bytes_read = file->Read(data, length);
+ Dart_EnableThreadInterrupter();
if (bytes_read >= 0) {
CObjectExternalUint8Array* external_array =
new CObjectExternalUint8Array(io_buffer);
@@ -948,7 +970,9 @@ CObject* File::ReadIntoRequest(const CObjectArray& request) {
Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
ASSERT(io_buffer != NULL);
uint8_t* data = io_buffer->value.as_external_typed_data.data;
+ Dart_DisableThreadInterrupter();
int64_t bytes_read = file->Read(data, length);
+ Dart_EnableThreadInterrupter();
if (bytes_read >= 0) {
CObjectExternalUint8Array* external_array =
new CObjectExternalUint8Array(io_buffer);
@@ -1028,8 +1052,10 @@ CObject* File::WriteFromRequest(const CObjectArray& request) {
}
start = 0;
}
+ Dart_DisableThreadInterrupter();
int64_t bytes_written =
file->Write(reinterpret_cast<void*>(buffer_start), length);
+ Dart_EnableThreadInterrupter();
if (!request[1]->IsTypedData()) {
delete[] buffer_start;
}
« no previous file with comments | « no previous file | runtime/bin/process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698