Merge "Fix reference counting for Assembly"

This commit is contained in:
Hans Boehm 2016-08-17 23:56:08 +00:00 committed by Gerrit Code Review
commit 3b6530507b
4 changed files with 5 additions and 7 deletions

View File

@ -23,7 +23,6 @@
#include <sys/mman.h>
#include <cutils/ashmem.h>
#include <cutils/atomic.h>
#define LOG_TAG "CodeCache"
#include <cutils/log.h>
@ -101,7 +100,7 @@ static mspace getMspace()
}
Assembly::Assembly(size_t size)
: mCount(1), mSize(0)
: mCount(0), mSize(0)
{
mBase = (uint32_t*)mspace_malloc(getMspace(), size);
LOG_ALWAYS_FATAL_IF(mBase == NULL,
@ -117,12 +116,12 @@ Assembly::~Assembly()
void Assembly::incStrong(const void*) const
{
android_atomic_inc(&mCount);
mCount.fetch_add(1, std::memory_order_relaxed);
}
void Assembly::decStrong(const void*) const
{
if (android_atomic_dec(&mCount) == 1) {
if (mCount.fetch_sub(1, std::memory_order_acq_rel) == 1) {
delete this;
}
}

View File

@ -19,6 +19,7 @@
#ifndef ANDROID_CODECACHE_H
#define ANDROID_CODECACHE_H
#include <atomic>
#include <stdint.h>
#include <pthread.h>
#include <sys/types.h>
@ -69,7 +70,7 @@ public:
typedef void weakref_type;
private:
mutable int32_t mCount;
mutable std::atomic<int32_t> mCount;
uint32_t* mBase;
size_t mSize;
};

View File

@ -34,7 +34,6 @@
#include <sys/mman.h>
#include <cutils/ashmem.h>
#include <cutils/atomic.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>

View File

@ -34,7 +34,6 @@
#include <sys/mman.h>
#include <cutils/ashmem.h>
#include <cutils/atomic.h>
#include <cutils/log.h>
#define __STDC_FORMAT_MACROS