Merge "Remove useless refCounting from FileMap."
This commit is contained in:
commit
c40cf1ce9d
4 changed files with 8 additions and 32 deletions
|
|
@ -63,6 +63,8 @@ public:
|
||||||
bool create(const char* origFileName, int fd,
|
bool create(const char* origFileName, int fd,
|
||||||
off64_t offset, size_t length, bool readOnly);
|
off64_t offset, size_t length, bool readOnly);
|
||||||
|
|
||||||
|
~FileMap(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the name of the file this map came from, if known.
|
* Return the name of the file this map came from, if known.
|
||||||
*/
|
*/
|
||||||
|
|
@ -83,19 +85,6 @@ public:
|
||||||
*/
|
*/
|
||||||
off64_t getDataOffset(void) const { return mDataOffset; }
|
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
|
* This maps directly to madvise() values, but allows us to avoid
|
||||||
* including <sys/mman.h> everywhere.
|
* including <sys/mman.h> everywhere.
|
||||||
|
|
@ -112,15 +101,12 @@ public:
|
||||||
int advise(MapAdvice advice);
|
int advise(MapAdvice advice);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// don't delete objects; call release()
|
|
||||||
~FileMap(void);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// these are not implemented
|
// these are not implemented
|
||||||
FileMap(const FileMap& src);
|
FileMap(const FileMap& src);
|
||||||
const FileMap& operator=(const FileMap& src);
|
const FileMap& operator=(const FileMap& src);
|
||||||
|
|
||||||
int mRefCount; // reference count
|
|
||||||
char* mFileName; // original file name, if known
|
char* mFileName; // original file name, if known
|
||||||
void* mBasePtr; // base of mmap area; page aligned
|
void* mBasePtr; // base of mmap area; page aligned
|
||||||
size_t mBaseLength; // length, measured from "mBasePtr"
|
size_t mBaseLength; // length, measured from "mBasePtr"
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ using namespace android;
|
||||||
|
|
||||||
// Constructor. Create an empty object.
|
// Constructor. Create an empty object.
|
||||||
FileMap::FileMap(void)
|
FileMap::FileMap(void)
|
||||||
: mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
|
: mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
|
||||||
mDataPtr(NULL), mDataLength(0)
|
mDataPtr(NULL), mDataLength(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -56,11 +56,6 @@ FileMap::FileMap(void)
|
||||||
// Destructor.
|
// Destructor.
|
||||||
FileMap::~FileMap(void)
|
FileMap::~FileMap(void)
|
||||||
{
|
{
|
||||||
assert(mRefCount == 0);
|
|
||||||
|
|
||||||
//printf("+++ removing FileMap %p %zu\n", mDataPtr, mDataLength);
|
|
||||||
|
|
||||||
mRefCount = -100; // help catch double-free
|
|
||||||
if (mFileName != NULL) {
|
if (mFileName != NULL) {
|
||||||
free(mFileName);
|
free(mFileName);
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +129,6 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le
|
||||||
|
|
||||||
void* ptr;
|
void* ptr;
|
||||||
|
|
||||||
assert(mRefCount == 1);
|
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
assert(offset >= 0);
|
assert(offset >= 0);
|
||||||
assert(length > 0);
|
assert(length > 0);
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,7 @@ Tokenizer::Tokenizer(const String8& filename, FileMap* fileMap, char* buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
Tokenizer::~Tokenizer() {
|
Tokenizer::~Tokenizer() {
|
||||||
if (mFileMap) {
|
delete mFileMap;
|
||||||
mFileMap->release();
|
|
||||||
}
|
|
||||||
if (mOwnBuffer) {
|
if (mOwnBuffer) {
|
||||||
delete[] mBuffer;
|
delete[] mBuffer;
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +72,7 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
|
||||||
fileMap->advise(FileMap::SEQUENTIAL);
|
fileMap->advise(FileMap::SEQUENTIAL);
|
||||||
buffer = static_cast<char*>(fileMap->getDataPtr());
|
buffer = static_cast<char*>(fileMap->getDataPtr());
|
||||||
} else {
|
} else {
|
||||||
fileMap->release();
|
delete fileMap;
|
||||||
fileMap = NULL;
|
fileMap = NULL;
|
||||||
|
|
||||||
// Fall back to reading into a buffer since we can't mmap files in sysfs.
|
// Fall back to reading into a buffer since we can't mmap files in sysfs.
|
||||||
|
|
|
||||||
|
|
@ -321,9 +321,7 @@ struct ZipArchive {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (directory_map != NULL) {
|
delete directory_map;
|
||||||
directory_map->release();
|
|
||||||
}
|
|
||||||
free(hash_table);
|
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;
|
android::FileMap* file_map = new android::FileMap;
|
||||||
const bool success = file_map->create(debug_file_name, fd, start, length, read_only);
|
const bool success = file_map->create(debug_file_name, fd, start, length, read_only);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
file_map->release();
|
delete file_map;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1170,7 +1168,7 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle,
|
||||||
const int32_t error = ExtractToMemory(handle, entry,
|
const int32_t error = ExtractToMemory(handle, entry,
|
||||||
reinterpret_cast<uint8_t*>(map->getDataPtr()),
|
reinterpret_cast<uint8_t*>(map->getDataPtr()),
|
||||||
map->getDataLength());
|
map->getDataLength());
|
||||||
map->release();
|
delete map;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue