summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-02-23 15:43:35 +0000
committerNarayan Kamath <narayan@google.com>2015-02-23 15:49:43 +0000
commit6832a7a4e04c84192f0bafc6ac990fc79cd13882 (patch)
treee8c0940ae4a25e96db0ad84985991731f2b1b8f4
parentf1ac6917da172dd3e6829bac41fcbf23e96da079 (diff)
downloadsystem_core-6832a7a4e04c84192f0bafc6ac990fc79cd13882.zip
system_core-6832a7a4e04c84192f0bafc6ac990fc79cd13882.tar.gz
system_core-6832a7a4e04c84192f0bafc6ac990fc79cd13882.tar.bz2
Remove useless refCounting from FileMap.
Nobody ever called acquire() so release() was always equivalent to delete. Just use delete instead so that people can use unique_ptr directly (or shared_ptr if they really want refcounts). Change-Id: I9e3ad5e0f6a4fcc4e02e5a2ff7ef9514fe234415
-rw-r--r--include/utils/FileMap.h18
-rw-r--r--libutils/FileMap.cpp8
-rw-r--r--libutils/Tokenizer.cpp6
-rw-r--r--libziparchive/zip_archive.cc8
4 files changed, 8 insertions, 32 deletions
diff --git a/include/utils/FileMap.h b/include/utils/FileMap.h
index 6c0aa52..f70fc92 100644
--- a/include/utils/FileMap.h
+++ b/include/utils/FileMap.h
@@ -63,6 +63,8 @@ public:
bool create(const char* origFileName, int fd,
off64_t offset, size_t length, bool readOnly);
+ ~FileMap(void);
+
/*
* Return the name of the file this map came from, if known.
*/
@@ -84,19 +86,6 @@ public:
off64_t getDataOffset(void) const { return mDataOffset; }
/*
- * Get a "copy" of the object.
- */
- FileMap* acquire(void) { mRefCount++; return this; }
-
- /*
- * Call this when mapping is no longer needed.
- */
- void release(void) {
- if (--mRefCount <= 0)
- delete this;
- }
-
- /*
* This maps directly to madvise() values, but allows us to avoid
* including <sys/mman.h> everywhere.
*/
@@ -112,15 +101,12 @@ public:
int advise(MapAdvice advice);
protected:
- // don't delete objects; call release()
- ~FileMap(void);
private:
// these are not implemented
FileMap(const FileMap& src);
const FileMap& operator=(const FileMap& src);
- int mRefCount; // reference count
char* mFileName; // original file name, if known
void* mBasePtr; // base of mmap area; page aligned
size_t mBaseLength; // length, measured from "mBasePtr"
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index 0af066f..91e45d8 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -48,7 +48,7 @@ using namespace android;
// Constructor. Create an empty object.
FileMap::FileMap(void)
- : mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
+ : mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
mDataPtr(NULL), mDataLength(0)
{
}
@@ -56,11 +56,6 @@ FileMap::FileMap(void)
// Destructor.
FileMap::~FileMap(void)
{
- assert(mRefCount == 0);
-
- //printf("+++ removing FileMap %p %zu\n", mDataPtr, mDataLength);
-
- mRefCount = -100; // help catch double-free
if (mFileName != NULL) {
free(mFileName);
}
@@ -134,7 +129,6 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le
void* ptr;
- assert(mRefCount == 1);
assert(fd >= 0);
assert(offset >= 0);
assert(length > 0);
diff --git a/libutils/Tokenizer.cpp b/libutils/Tokenizer.cpp
index 7067533..610002f 100644
--- a/libutils/Tokenizer.cpp
+++ b/libutils/Tokenizer.cpp
@@ -43,9 +43,7 @@ Tokenizer::Tokenizer(const String8& filename, FileMap* fileMap, char* buffer,
}
Tokenizer::~Tokenizer() {
- if (mFileMap) {
- mFileMap->release();
- }
+ delete mFileMap;
if (mOwnBuffer) {
delete[] mBuffer;
}
@@ -74,7 +72,7 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
fileMap->advise(FileMap::SEQUENTIAL);
buffer = static_cast<char*>(fileMap->getDataPtr());
} else {
- fileMap->release();
+ delete fileMap;
fileMap = NULL;
// Fall back to reading into a buffer since we can't mmap files in sysfs.
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index afc122d..ebbab9f 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -321,9 +321,7 @@ struct ZipArchive {
close(fd);
}
- if (directory_map != NULL) {
- directory_map->release();
- }
+ delete directory_map;
free(hash_table);
}
};
@@ -335,7 +333,7 @@ static android::FileMap* MapFileSegment(const int fd, const off64_t start,
android::FileMap* file_map = new android::FileMap;
const bool success = file_map->create(debug_file_name, fd, start, length, read_only);
if (!success) {
- file_map->release();
+ delete file_map;
return NULL;
}
@@ -1170,7 +1168,7 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle,
const int32_t error = ExtractToMemory(handle, entry,
reinterpret_cast<uint8_t*>(map->getDataPtr()),
map->getDataLength());
- map->release();
+ delete map;
return error;
}