Merge "Fix reference counting for Assembly"
This commit is contained in:
commit
3b6530507b
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
#include <sys/mman.h>
|
||||
#include <cutils/ashmem.h>
|
||||
#include <cutils/atomic.h>
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
#include <sys/mman.h>
|
||||
#include <cutils/ashmem.h>
|
||||
#include <cutils/atomic.h>
|
||||
#include <cutils/log.h>
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
|
|
Loading…
Reference in New Issue