* UCW Library -- Memory Pools (One-Time Allocation)
*
* (c) 1997--2014 Martin Mares <mj@ucw.cz>
- * (c) 2007 Pavel Charvat <pchar@ucw.cz>
+ * (c) 2007--2014 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#define MP_SIZE_MAX (~0U - MP_CHUNK_TAIL - CPU_PAGE_SIZE)
struct mempool_chunk {
+#ifdef CONFIG_DEBUG
+ struct mempool *pool; // Can be useful when analysing coredump for memory leaks
+#endif
struct mempool_chunk *next;
uns size;
};
struct mempool *pool = (void *)chunk - chunk_size;
DBG("Creating mempool %p with %u bytes long chunks", pool, chunk_size);
chunk->next = NULL;
+#ifdef CONFIG_DEBUG
+ chunk->pool = pool;
+#endif
*pool = (struct mempool) {
.allocator = {
.alloc = mp_allocator_alloc,
pool->unused = chunk->next;
}
else
- chunk = mp_new_chunk(pool->chunk_size);
+ {
+ chunk = mp_new_chunk(pool->chunk_size);
+#ifdef CONFIG_DEBUG
+ chunk->pool = pool;
+#endif
+ }
chunk->next = pool->state.last[0];
pool->state.last[0] = chunk;
pool->state.free[0] = pool->chunk_size - size;
uns aligned = ALIGN_TO(size, CPU_STRUCT_ALIGN);
chunk = mp_new_big_chunk(aligned);
chunk->next = pool->state.last[1];
+#ifdef CONFIG_DEBUG
+ chunk->pool = pool;
+#endif
pool->state.last[1] = chunk;
pool->state.free[1] = aligned - size;
return pool->last_big = (void *)chunk - aligned;