C Collections

clrucache · Section 3

clrucache_destroy

clrucache_destroy - destroy an LRU cache and invalidate the handle

C Collections (libccollections, -lccollections)

#include <ccollections/clrucache.h>
 
clrucache_destroy(name);

Waits until every in-flight resolved use of the handle has stopped,
then evicts all the remaining entries, calling the eviction callback
for each one with the lock of the owning segment held. After that it
destroys the map of every segment, frees all the memory and sets name
to CCACHE_NULL.

name  The cache variable to destroy. The macro sets it to
      CCACHE_NULL after the destruction

Calling it when name is CCACHE_NULL is safe, and it does
nothing.
A call on a stale handle is a FATAL ERROR: It calls abort() and raises
SIGABRT, and it is never a silent double-free. A handle is stale when
an earlier call destroyed it, or when another thread destroys it at
the same time. A forged value or garbage is a fatal error too. The
handle carries a generation tag that the library checks before it
touches the cache behind it, so such a value is always detected and
never dereferenced.
A concurrent, ordinary call to clrucache_get_full(),
clrucache_set_full(), clrucache_size() or clrucache_capacity() on the
same handle is not misuse; this call waits for that call to finish
before it frees anything.
 
The macro evaluates name exactly once. It must be a modifiable lvalue,
such as a variable or an element of an array, so with an expression
that has a side effect, such as handles[i++], it destroys and clears
one element.

ccache_destroy(3), ccache_construct(3), clrucache_create_full(3)