cmempool · Section 3
cmempool_used_count
NAME
cmempool_used_count - report how many pool elements are in use
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cmempool.h> size_t cmempool_used_count(cmempool *mp);
DESCRIPTION
Returns the number of pool-owned elements that callers hold at the moment. An element sitting in a thread's cache has left the shared free list, but the pool gave it to nobody, so it doesn't count as used. A dynamic fallback entry isn't counted either; cmempool_dynamic_allocs_count(3) reports those.
PARAMETERS
mp Memory pool to query (must not be NULL)
RETURN VALUE
Returns the number of elements in use at the moment
NOTES
The count is exact whenever the pool is quiet. If other threads allocate or free while the call runs, the result is a snapshot that can be stale by the time the call returns, as any count of something that keeps moving is. On a quiet pool the result never goes above cmempool_total_capacity(). Under concurrent allocation on a pool with a cache for each thread it can be a few entries above that for a short time, but never above the physical slot count that cmempool_allocated_bytes(3) reports. cmempool_total_capacity(3) explains why. A NULL mp is a fatal error: The call prints a message and ends the process with abort(), in every build.
THREAD SAFETY
Thread-safe when the pool was created with single_threaded = false. The call takes the pool's lock and walks the cache of each thread, so it belongs on a cold path; don't use it inside a hot loop.
SEE ALSO
cmempool_total_capacity(3), cmempool_dynamic_allocs_count(3), cmempool_create_mp(3)