|
|
@ -137,26 +137,23 @@ static cam_cmd_power *power_set_wait(cam_cmd_power *power, int16_t delay_ms) { |
|
|
|
// *** MemoryManager ***
|
|
|
|
// *** MemoryManager ***
|
|
|
|
|
|
|
|
|
|
|
|
void *MemoryManager::alloc_buf(int size, uint32_t *handle) { |
|
|
|
void *MemoryManager::alloc_buf(int size, uint32_t *handle) { |
|
|
|
lock.lock(); |
|
|
|
|
|
|
|
void *ptr; |
|
|
|
void *ptr; |
|
|
|
if (!cached_allocations[size].empty()) { |
|
|
|
auto &cache = cached_allocations[size]; |
|
|
|
ptr = cached_allocations[size].front(); |
|
|
|
if (!cache.empty()) { |
|
|
|
cached_allocations[size].pop(); |
|
|
|
ptr = cache.front(); |
|
|
|
|
|
|
|
cache.pop(); |
|
|
|
*handle = handle_lookup[ptr]; |
|
|
|
*handle = handle_lookup[ptr]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ptr = alloc_w_mmu_hdl(video0_fd, size, handle); |
|
|
|
ptr = alloc_w_mmu_hdl(video0_fd, size, handle); |
|
|
|
handle_lookup[ptr] = *handle; |
|
|
|
handle_lookup[ptr] = *handle; |
|
|
|
size_lookup[ptr] = size; |
|
|
|
size_lookup[ptr] = size; |
|
|
|
} |
|
|
|
} |
|
|
|
lock.unlock(); |
|
|
|
|
|
|
|
memset(ptr, 0, size); |
|
|
|
memset(ptr, 0, size); |
|
|
|
return ptr; |
|
|
|
return ptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MemoryManager::free(void *ptr) { |
|
|
|
void MemoryManager::free(void *ptr) { |
|
|
|
lock.lock(); |
|
|
|
|
|
|
|
cached_allocations[size_lookup[ptr]].push(ptr); |
|
|
|
cached_allocations[size_lookup[ptr]].push(ptr); |
|
|
|
lock.unlock(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MemoryManager::~MemoryManager() { |
|
|
|
MemoryManager::~MemoryManager() { |
|
|
|