#define POOL_DBG_NO_GLOBAL 0x00000010 // disable global pools
#define POOL_DBG_NO_CACHE 0x00000020 // disable thread-local pool caches
#define POOL_DBG_CALLER 0x00000040 // trace last caller's location
+#define POOL_DBG_TAG 0x00000080 // place a tag at the end of the area
/* This is the head of a thread-local cache */
* this location is used to keep a pointer to the pool the object was
* allocated from, and verify it's freed into the appropriate one.
*/
-#ifdef DEBUG_MEMORY_POOLS
-
# define POOL_EXTRA_MARK (sizeof(void *))
# define POOL_DEBUG_SET_MARK(pool, item) \
do { \
typeof(pool) __p = (pool); \
typeof(item) __i = (item); \
+ if (likely(!(pool_debugging & POOL_DBG_TAG))) \
+ break; \
*(typeof(pool)*)(((char *)__i) + __p->size) = __p; \
} while (0)
do { \
typeof(pool) __p = (pool); \
typeof(item) __i = (item); \
+ if (likely(!(pool_debugging & POOL_DBG_TAG))) \
+ break; \
*(typeof(pool)*)(((char *)__i) + __p->size) = __builtin_return_address(0); \
} while (0)
do { \
typeof(pool) __p = (pool); \
typeof(item) __i = (item); \
+ if (likely(!(pool_debugging & POOL_DBG_TAG))) \
+ break; \
if (*(typeof(pool)*)(((char *)__i) + __p->size) != __p) \
ABORT_NOW(); \
} while (0)
-#else // DEBUG_MEMORY_POOLS
-
-# define POOL_EXTRA_MARK (0)
-# define POOL_DEBUG_SET_MARK(pool, item) do { } while (0)
-# define POOL_DEBUG_RESET_MARK(pool, item) do { } while (0)
-# define POOL_DEBUG_CHECK_MARK(pool, item) do { } while (0)
-
-#endif // DEBUG_MEMORY_POOLS
-
/* It's possible to trace callers of pool_free() by placing their pointer
* after the end of the area and the optional mark above, which means the
* end of the allocated array.
#endif
#if defined(DEBUG_POOL_TRACING)
POOL_DBG_CALLER |
+#endif
+#if defined(DEBUG_MEMORY_POOLS)
+ POOL_DBG_TAG |
#endif
0;
* Note: for the LRU cache, we need to store 2 doubly-linked lists.
*/
- extra_mark = POOL_EXTRA_MARK;
+ extra_mark = (pool_debugging & POOL_DBG_TAG) ? POOL_EXTRA_MARK : 0;
extra_caller = (pool_debugging & POOL_DBG_CALLER) ? POOL_EXTRA_CALLER : 0;
extra = extra_mark + extra_caller;