fix a rookie mistake causing Singleton<> to be a "multiton". Also improve the BufferMapper's debugging, but turn it off.
Squashed commit of the following:
commit 04e9cae7f806bd65f2cfe35c011b47a36773bbe5
Author: Mathias Agopian <mathias@google.com>
Date: Wed Apr 15 18:30:30 2009 -0700
fix and improve BufferMapper's tracking of mapped buffers.
commit 1a8deaed15811092b2349cc3c40cafb5f722046c
Author: Mathias Agopian <mathias@google.com>
Date: Wed Apr 15 00:52:02 2009 -0700
fix some bugs with the Singleton<> class. untested.
commit ed01cc06ad70cf640ce1258f01189cb1a96fd3a8
Author: Mathias Agopian <mathias@google.com>
Date: Tue Apr 14 19:29:25 2009 -0700
some work to debug the Singleton<> template.
diff --git a/libs/surfaceflinger/BufferAllocator.cpp b/libs/surfaceflinger/BufferAllocator.cpp
index 96a2c32..28fe810 100644
--- a/libs/surfaceflinger/BufferAllocator.cpp
+++ b/libs/surfaceflinger/BufferAllocator.cpp
@@ -19,6 +19,8 @@
#include <utils/CallStack.h>
#include <cutils/ashmem.h>
#include <cutils/log.h>
+
+#include <utils/Singleton.h>
#include <utils/String8.h>
#include <ui/BufferMapper.h>
@@ -32,6 +34,9 @@
namespace android {
// ---------------------------------------------------------------------------
+template<class BufferAllocator> Mutex Singleton<BufferAllocator>::sLock;
+template<> BufferAllocator* Singleton<BufferAllocator>::sInstance(0);
+
Mutex BufferAllocator::sLock;
KeyedVector<buffer_handle_t, BufferAllocator::alloc_rec_t> BufferAllocator::sAllocList;
@@ -106,7 +111,14 @@
#if ANDROID_GRALLOC_DEBUG
void* base = (void*)(handle->data[2]);
+#endif
+
+ status_t err = mAllocDev->free(mAllocDev, handle);
+ LOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
+
+#if ANDROID_GRALLOC_DEBUG
if (base) {
+ LOGD("freeing mapped handle %p from:", handle);
CallStack s;
s.update();
s.dump("");
@@ -114,9 +126,6 @@
}
#endif
- status_t err = mAllocDev->free(mAllocDev, handle);
- LOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
-
if (err == NO_ERROR) {
Mutex::Autolock _l(sLock);
KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
@@ -129,7 +138,7 @@
status_t BufferAllocator::map(buffer_handle_t handle, void** addr)
{
Mutex::Autolock _l(mLock);
- status_t err = BufferMapper::get().map(handle, addr);
+ status_t err = BufferMapper::get().map(handle, addr, this);
if (err == NO_ERROR) {
Mutex::Autolock _l(sLock);
KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
@@ -145,7 +154,7 @@
{
Mutex::Autolock _l(mLock);
gralloc_module_t* mod = (gralloc_module_t*)mAllocDev->common.module;
- status_t err = BufferMapper::get().unmap(handle);
+ status_t err = BufferMapper::get().unmap(handle, this);
if (err == NO_ERROR) {
Mutex::Autolock _l(sLock);
KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);