Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Fix reference counting for Assembly
Browse files Browse the repository at this point in the history
Use correct memory ordering.

Start the reference count at zero instead of one, thus giving us a
chance to actually deallocate something.

Remove remaining (unused) inclusions of cutils/atomic.h from
libpixelflinger.

Bug: 30838047

Change-Id: I3c6fd4a4861b3635cf398ca2aa3e915118100b10
  • Loading branch information
hboehm committed Aug 16, 2016
1 parent 7a746f3 commit e74dec4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
7 changes: 3 additions & 4 deletions libpixelflinger/codeflinger/CodeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <sys/mman.h>

#include <cutils/ashmem.h>
#include <cutils/atomic.h>
#define LOG_TAG "CodeCache"
#include <cutils/log.h>

Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion libpixelflinger/codeflinger/CodeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef ANDROID_CODECACHE_H
#define ANDROID_CODECACHE_H

#include <atomic>
#include <stdint.h>
#include <pthread.h>
#include <sys/types.h>
Expand Down Expand Up @@ -69,7 +70,7 @@ class Assembly
typedef void weakref_type;

private:
mutable int32_t mCount;
mutable std::atomic<int32_t> mCount;
uint32_t* mBase;
size_t mSize;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include <sys/mman.h>
#include <cutils/ashmem.h>
#include <cutils/atomic.h>

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include <sys/mman.h>
#include <cutils/ashmem.h>
#include <cutils/atomic.h>
#include <cutils/log.h>

#define __STDC_FORMAT_MACROS
Expand Down

0 comments on commit e74dec4

Please sign in to comment.