From: Josef 'Jeff' Sipek Date: Wed, 20 Jun 2018 11:50:38 +0000 (-0400) Subject: lib: Document datastack mempools X-Git-Tag: 2.3.9~1627 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe151c8b27a00986a2fcb93134ceeed6de371a32;p=thirdparty%2Fdovecot%2Fcore.git lib: Document datastack mempools --- diff --git a/src/lib/mempool-datastack.c b/src/lib/mempool-datastack.c index 6a66b118b0..e3971d1a99 100644 --- a/src/lib/mempool-datastack.c +++ b/src/lib/mempool-datastack.c @@ -3,6 +3,57 @@ #include "lib.h" #include "mempool.h" +/* + * The datastack pool is a thin wrapper around the datastack API. It exists + * to allow datastack allocations via the pool API. + * + * Note: Do not confuse it with the *unsafe* datastack pool. + * + * Implementation + * ============== + * + * A datastack pool maintains information about the datastack frame that was + * in use when the pool was created so it can sanity check all p_new(), + * p_malloc(), and p_realloc() calls. + * + * Creation + * -------- + * + * When a datastack pool is created, a new pool structure is allocated from + * the datastack (via t_new()). The current datastack frame number is saved + * into the pool's private data (struct datastack_pool). + * + * Allocation & Reallocation + * ------------------------- + * + * After verifying that the saved datastack frame id matches the currently + * active one, the p_malloc() and p_realloc() calls get directed to + * t_malloc0() and t_try_realloc(), respectively. There is no + * per-allocation information to track. + * + * Freeing + * ------- + * + * Freeing is a no-op unless the currently active data stack frame id is + * different from the one saved during pool creation, in which case the + * process panics. + * + * Clearing + * -------- + * + * A no-op. + * + * Destruction + * ----------- + * + * Since the memory backing the pool structure itself is allocated from the + * datastack via t_new(), the pool and all allocations it made are freed + * when the datastack frame is popped. + * + * Even though the pool maintains a reference count, no memory is freed when + * it reaches zero. Once the reference count reaches zero, the state of the + * pool is undefined and none of its memory maybe be used. + */ static const char *pool_data_stack_get_name(pool_t pool); static void pool_data_stack_ref(pool_t pool);