diff options
Diffstat (limited to 'libs/ui/BufferMapper.cpp')
| -rw-r--r-- | libs/ui/BufferMapper.cpp | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/libs/ui/BufferMapper.cpp b/libs/ui/BufferMapper.cpp index c7e439c3c968..e6ca239831fa 100644 --- a/libs/ui/BufferMapper.cpp +++ b/libs/ui/BufferMapper.cpp @@ -36,14 +36,17 @@ // --------------------------------------------------------------------------- // enable mapping debugging -#define DEBUG_MAPPINGS 1 +#define DEBUG_MAPPINGS 0 // never remove mappings from the list -#define DEBUG_MAPPINGS_KEEP_ALL 1 +#define DEBUG_MAPPINGS_KEEP_ALL 0 // --------------------------------------------------------------------------- namespace android { // --------------------------------------------------------------------------- +template<class BufferMapper> Mutex Singleton<BufferMapper>::sLock; +template<> BufferMapper* Singleton<BufferMapper>::sInstance(0); + BufferMapper::BufferMapper() : mAllocMod(0) { @@ -55,26 +58,26 @@ BufferMapper::BufferMapper() } } -status_t BufferMapper::map(buffer_handle_t handle, void** addr) +status_t BufferMapper::map(buffer_handle_t handle, void** addr, const void* id) { Mutex::Autolock _l(mLock); status_t err = mAllocMod->map(mAllocMod, handle, addr); LOGW_IF(err, "map(...) failed %d (%s)", err, strerror(-err)); #if DEBUG_MAPPINGS if (err == NO_ERROR) - logMapLocked(handle); + logMapLocked(handle, id); #endif return err; } -status_t BufferMapper::unmap(buffer_handle_t handle) +status_t BufferMapper::unmap(buffer_handle_t handle, const void* id) { Mutex::Autolock _l(mLock); status_t err = mAllocMod->unmap(mAllocMod, handle); LOGW_IF(err, "unmap(...) failed %d (%s)", err, strerror(-err)); #if DEBUG_MAPPINGS if (err == NO_ERROR) - logUnmapLocked(handle); + logUnmapLocked(handle, id); #endif return err; } @@ -94,49 +97,46 @@ status_t BufferMapper::unlock(buffer_handle_t handle) return err; } -void BufferMapper::logMapLocked(buffer_handle_t handle) +void BufferMapper::logMapLocked(buffer_handle_t handle, const void* id) { CallStack stack; stack.update(2); map_info_t info; + info.id = id; + info.stack = stack; + ssize_t index = mMapInfo.indexOfKey(handle); if (index >= 0) { - info = mMapInfo.valueAt(index); - } - - ssize_t stackIndex = info.callstacks.indexOfKey(stack); - if (stackIndex >= 0) { - info.callstacks.editValueAt(stackIndex) += 1; - } else { - info.callstacks.add(stack, 1); - } - - if (index < 0) { - info.count = 1; - mMapInfo.add(handle, info); + Vector<map_info_t>& infos = mMapInfo.editValueAt(index); + infos.add(info); } else { - info.count++; - mMapInfo.replaceValueAt(index, info); + Vector<map_info_t> infos; + infos.add(info); + mMapInfo.add(handle, infos); } } -void BufferMapper::logUnmapLocked(buffer_handle_t handle) +void BufferMapper::logUnmapLocked(buffer_handle_t handle, const void* id) { ssize_t index = mMapInfo.indexOfKey(handle); if (index < 0) { - LOGE("unmapping %p which doesn't exist!", handle); + LOGE("unmapping %p which doesn't exist in our map!", handle); return; } - map_info_t& info = mMapInfo.editValueAt(index); - info.count--; - if (info.count == 0) { -#if DEBUG_MAPPINGS_KEEP_ALL - info.callstacks.clear(); -#else + Vector<map_info_t>& infos = mMapInfo.editValueAt(index); + ssize_t count = infos.size(); + for (int i=0 ; i<count ; ) { + if (infos[i].id == id) { + infos.removeAt(i); + --count; + } else { + ++i; + } + } + if (count == 0) { mMapInfo.removeItemsAt(index, 1); -#endif } } @@ -149,11 +149,11 @@ void BufferMapper::dump(buffer_handle_t handle) return; } - const map_info_t& info = mMapInfo.valueAt(index); - LOGD("dumping buffer_handle_t %p mappings (count=%d)", handle, info.count); - for (size_t i=0 ; i<info.callstacks.size() ; i++) { - LOGD("#%d, count=%d", i, info.callstacks.valueAt(i)); - info.callstacks.keyAt(i).dump(); + const Vector<map_info_t>& infos = mMapInfo.valueAt(index); + ssize_t count = infos.size(); + for (int i=0 ; i<count ; i++) { + LOGD("#%d", i); + infos[i].stack.dump(); } } |