summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Boehm2016-08-10 20:44:14 -0500
committerHans Boehm2016-08-16 12:12:43 -0500
commite74dec4a390f95177946be4942a45c8be8720ed0 (patch)
tree2771c9e9755c559b5324b7b39da9c1bb2c20ed82 /libpixelflinger
parent7a746f3a6850198b7f1cad7f22befe9ca48b47fd (diff)
downloadplatform-system-core-e74dec4a390f95177946be4942a45c8be8720ed0.tar.gz
platform-system-core-e74dec4a390f95177946be4942a45c8be8720ed0.tar.xz
platform-system-core-e74dec4a390f95177946be4942a45c8be8720ed0.zip
Fix reference counting for Assembly
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
Diffstat (limited to 'libpixelflinger')
-rw-r--r--libpixelflinger/codeflinger/CodeCache.cpp7
-rw-r--r--libpixelflinger/codeflinger/CodeCache.h3
-rw-r--r--libpixelflinger/tests/arch-arm64/assembler/arm64_assembler_test.cpp1
-rw-r--r--libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp1
4 files changed, 5 insertions, 7 deletions
diff --git a/libpixelflinger/codeflinger/CodeCache.cpp b/libpixelflinger/codeflinger/CodeCache.cpp
index 4b498c144..ae3851914 100644
--- a/libpixelflinger/codeflinger/CodeCache.cpp
+++ b/libpixelflinger/codeflinger/CodeCache.cpp
@@ -23,7 +23,6 @@
23#include <sys/mman.h> 23#include <sys/mman.h>
24 24
25#include <cutils/ashmem.h> 25#include <cutils/ashmem.h>
26#include <cutils/atomic.h>
27#define LOG_TAG "CodeCache" 26#define LOG_TAG "CodeCache"
28#include <cutils/log.h> 27#include <cutils/log.h>
29 28
@@ -101,7 +100,7 @@ static mspace getMspace()
101} 100}
102 101
103Assembly::Assembly(size_t size) 102Assembly::Assembly(size_t size)
104 : mCount(1), mSize(0) 103 : mCount(0), mSize(0)
105{ 104{
106 mBase = (uint32_t*)mspace_malloc(getMspace(), size); 105 mBase = (uint32_t*)mspace_malloc(getMspace(), size);
107 LOG_ALWAYS_FATAL_IF(mBase == NULL, 106 LOG_ALWAYS_FATAL_IF(mBase == NULL,
@@ -117,12 +116,12 @@ Assembly::~Assembly()
117 116
118void Assembly::incStrong(const void*) const 117void Assembly::incStrong(const void*) const
119{ 118{
120 android_atomic_inc(&mCount); 119 mCount.fetch_add(1, std::memory_order_relaxed);
121} 120}
122 121
123void Assembly::decStrong(const void*) const 122void Assembly::decStrong(const void*) const
124{ 123{
125 if (android_atomic_dec(&mCount) == 1) { 124 if (mCount.fetch_sub(1, std::memory_order_acq_rel) == 1) {
126 delete this; 125 delete this;
127 } 126 }
128} 127}
diff --git a/libpixelflinger/codeflinger/CodeCache.h b/libpixelflinger/codeflinger/CodeCache.h
index c0e0684ef..93264530f 100644
--- a/libpixelflinger/codeflinger/CodeCache.h
+++ b/libpixelflinger/codeflinger/CodeCache.h
@@ -19,6 +19,7 @@
19#ifndef ANDROID_CODECACHE_H 19#ifndef ANDROID_CODECACHE_H
20#define ANDROID_CODECACHE_H 20#define ANDROID_CODECACHE_H
21 21
22#include <atomic>
22#include <stdint.h> 23#include <stdint.h>
23#include <pthread.h> 24#include <pthread.h>
24#include <sys/types.h> 25#include <sys/types.h>
@@ -69,7 +70,7 @@ public:
69 typedef void weakref_type; 70 typedef void weakref_type;
70 71
71private: 72private:
72 mutable int32_t mCount; 73 mutable std::atomic<int32_t> mCount;
73 uint32_t* mBase; 74 uint32_t* mBase;
74 size_t mSize; 75 size_t mSize;
75}; 76};
diff --git a/libpixelflinger/tests/arch-arm64/assembler/arm64_assembler_test.cpp b/libpixelflinger/tests/arch-arm64/assembler/arm64_assembler_test.cpp
index 5f5879784..63642c4b1 100644
--- a/libpixelflinger/tests/arch-arm64/assembler/arm64_assembler_test.cpp
+++ b/libpixelflinger/tests/arch-arm64/assembler/arm64_assembler_test.cpp
@@ -34,7 +34,6 @@
34 34
35#include <sys/mman.h> 35#include <sys/mman.h>
36#include <cutils/ashmem.h> 36#include <cutils/ashmem.h>
37#include <cutils/atomic.h>
38 37
39#define __STDC_FORMAT_MACROS 38#define __STDC_FORMAT_MACROS
40#include <inttypes.h> 39#include <inttypes.h>
diff --git a/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp b/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp
index b680b60f4..e8c4626b2 100644
--- a/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp
+++ b/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp
@@ -34,7 +34,6 @@
34 34
35#include <sys/mman.h> 35#include <sys/mman.h>
36#include <cutils/ashmem.h> 36#include <cutils/ashmem.h>
37#include <cutils/atomic.h>
38#include <cutils/log.h> 37#include <cutils/log.h>
39 38
40#define __STDC_FORMAT_MACROS 39#define __STDC_FORMAT_MACROS