auto import from //branches/cupcake/...@125939

This commit is contained in:
The Android Open Source Project 2009-01-09 17:51:23 -08:00 committed by Alex Ray
parent 7810449ca1
commit 046e40caa0
3 changed files with 43 additions and 11 deletions

View File

@ -32,7 +32,10 @@ class MemoryHeapBase : public virtual BnMemoryHeap
public:
enum {
READ_ONLY = IMemoryHeap::READ_ONLY,
MAP_ONCE = IMemoryHeap::MAP_ONCE
MAP_ONCE = IMemoryHeap::MAP_ONCE,
// memory won't be mapped locally, but will be mapped in the remote
// process.
DONT_MAP_LOCALLY = 0x00000100
};
/*

View File

@ -17,6 +17,7 @@
#ifndef ANDROID_REF_BASE_H
#define ANDROID_REF_BASE_H
#include <cutils/atomic.h>
#include <utils/TextOutput.h>
#include <stdint.h>
@ -142,6 +143,29 @@ private:
// ---------------------------------------------------------------------------
template <class T>
class LightRefBase
{
public:
inline LightRefBase() : mCount(0) { }
inline void incStrong(const void* id) const {
android_atomic_inc(&mCount);
}
inline void decStrong(const void* id) const {
if (android_atomic_dec(&mCount) == 1) {
delete static_cast<const T*>(this);
}
}
protected:
inline ~LightRefBase() { }
private:
mutable volatile int32_t mCount;
};
// ---------------------------------------------------------------------------
template <typename T>
class sp
{

View File

@ -119,19 +119,24 @@ status_t MemoryHeapBase::mapfd(int fd, size_t size)
// if it didn't work, let mmap() fail.
}
void* base = (uint8_t*)mmap(0, size,
PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (base == MAP_FAILED) {
LOGE("mmap(fd=%d, size=%u) failed (%s)",
fd, uint32_t(size), strerror(errno));
close(fd);
return -errno;
if ((mFlags & DONT_MAP_LOCALLY) == 0) {
void* base = (uint8_t*)mmap(0, size,
PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (base == MAP_FAILED) {
LOGE("mmap(fd=%d, size=%u) failed (%s)",
fd, uint32_t(size), strerror(errno));
close(fd);
return -errno;
}
//LOGD("mmap(fd=%d, base=%p, size=%lu)", fd, base, size);
mBase = base;
mNeedUnmap = true;
} else {
mBase = 0; // not MAP_FAILED
mNeedUnmap = false;
}
//LOGD("mmap(fd=%d, base=%p, size=%lu)", fd, base, size);
mFD = fd;
mBase = base;
mSize = size;
mNeedUnmap = true;
return NO_ERROR;
}