aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/util/memmapped_file_system.cc
diff options
context:
space:
mode:
authorGravatar Vijay Vasudevan <vrv@google.com>2016-06-16 18:04:10 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-06-16 19:16:41 -0700
commit209c006578483460e98c114a69d4b9ed6b95efed (patch)
tree0d0fa06e6472beea7291a2ea7bedc562e0a7f6dc /tensorflow/core/util/memmapped_file_system.cc
parent92753d80cf09efd6e9b9156e7ad08b3203214cec (diff)
TensorFlow: minor change functions in Env interface.
Switches to return a std::unique_ptr<> to convey transfer of ownership. Keeps existing functions temporarily for backwards compatibility. Change file_system.h interface to switch entirely to the new interface, change all callers. If this breaks someone in the public, the interface change should be straightforward. Change: 125127028
Diffstat (limited to 'tensorflow/core/util/memmapped_file_system.cc')
-rw-r--r--tensorflow/core/util/memmapped_file_system.cc25
1 files changed, 12 insertions, 13 deletions
diff --git a/tensorflow/core/util/memmapped_file_system.cc b/tensorflow/core/util/memmapped_file_system.cc
index a276421226..6d02595b8a 100644
--- a/tensorflow/core/util/memmapped_file_system.cc
+++ b/tensorflow/core/util/memmapped_file_system.cc
@@ -87,8 +87,8 @@ bool MemmappedFileSystem::FileExists(const string& fname) {
return dir_element != directory_.end();
}
-Status MemmappedFileSystem::NewRandomAccessFile(const string& filename,
- RandomAccessFile** result) {
+Status MemmappedFileSystem::NewRandomAccessFile(
+ const string& filename, std::unique_ptr<RandomAccessFile>* result) {
if (!mapped_memory_) {
return errors::FailedPrecondition("MemmappedEnv is not initialized");
}
@@ -96,14 +96,14 @@ Status MemmappedFileSystem::NewRandomAccessFile(const string& filename,
if (dir_element == directory_.end()) {
return errors::NotFound("Region ", filename, " is not found");
}
- *result = new RandomAccessFileFromMemmapped(
+ result->reset(new RandomAccessFileFromMemmapped(
GetMemoryWithOffset(dir_element->second.offset),
- dir_element->second.length);
+ dir_element->second.length));
return Status::OK();
}
Status MemmappedFileSystem::NewReadOnlyMemoryRegionFromFile(
- const string& filename, ReadOnlyMemoryRegion** result) {
+ const string& filename, std::unique_ptr<ReadOnlyMemoryRegion>* result) {
if (!mapped_memory_) {
return errors::FailedPrecondition("MemmappedEnv is not initialized");
}
@@ -111,9 +111,9 @@ Status MemmappedFileSystem::NewReadOnlyMemoryRegionFromFile(
if (dir_element == directory_.end()) {
return errors::NotFound("Region ", filename, " is not found");
}
- *result = new ReadOnlyMemoryRegionFromMemmapped(
+ result->reset(new ReadOnlyMemoryRegionFromMemmapped(
GetMemoryWithOffset(dir_element->second.offset),
- dir_element->second.length);
+ dir_element->second.length));
return Status::OK();
}
@@ -130,12 +130,12 @@ Status MemmappedFileSystem::GetFileSize(const string& filename, uint64* size) {
}
Status MemmappedFileSystem::NewWritableFile(const string& filename,
- WritableFile** wf) {
+ std::unique_ptr<WritableFile>* wf) {
return errors::Unimplemented("memmapped format doesn't support writing");
}
-Status MemmappedFileSystem::NewAppendableFile(const string& filename,
- WritableFile** result) {
+Status MemmappedFileSystem::NewAppendableFile(
+ const string& filename, std::unique_ptr<WritableFile>* result) {
return errors::Unimplemented("memmapped format doesn't support writing");
}
@@ -170,9 +170,8 @@ constexpr char MemmappedFileSystem::kMemmappedPackageDefaultGraphDef[];
Status MemmappedFileSystem::InitializeFromFile(Env* env,
const string& filename) {
- ReadOnlyMemoryRegion* region;
- TF_RETURN_IF_ERROR(env->NewReadOnlyMemoryRegionFromFile(filename, &region));
- mapped_memory_.reset(region);
+ TF_RETURN_IF_ERROR(
+ env->NewReadOnlyMemoryRegionFromFile(filename, &mapped_memory_));
directory_.clear();
if (mapped_memory_->length() <= sizeof(uint64)) {
return errors::DataLoss("Corrupted memmapped model file: ", filename,