Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 046e40ca authored by The Android Open Source Project's avatar The Android Open Source Project Committed by Alex Ray
Browse files

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

parent 7810449c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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
    };

    /* 
+24 −0
Original line number Diff line number Diff line
@@ -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
{
+15 −10
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ status_t MemoryHeapBase::mapfd(int fd, size_t size)
        // if it didn't work, let mmap() fail.
    }

    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) {
@@ -128,10 +129,14 @@ status_t MemoryHeapBase::mapfd(int fd, size_t size)
            return -errno;
        }
        //LOGD("mmap(fd=%d, base=%p, size=%lu)", fd, base, size);
    mFD = fd;
        mBase = base;
    mSize = size;
        mNeedUnmap = true;
    } else  {
        mBase = 0; // not MAP_FAILED
        mNeedUnmap = false;
    }
    mFD = fd;
    mSize = size;
    return NO_ERROR;
}