mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 21:51:05 +00:00
xarray: Destroy an XArray
This function frees all the internal memory allocated to the xarray and reinitialises it to be empty. Signed-off-by: Matthew Wilcox <willy@infradead.org>
This commit is contained in:
parent
80a0a1a9a3
commit
687149fca1
3 changed files with 63 additions and 0 deletions
28
lib/xarray.c
28
lib/xarray.c
|
@ -1524,6 +1524,34 @@ unsigned int xa_extract(struct xarray *xa, void **dst, unsigned long start,
|
|||
}
|
||||
EXPORT_SYMBOL(xa_extract);
|
||||
|
||||
/**
|
||||
* xa_destroy() - Free all internal data structures.
|
||||
* @xa: XArray.
|
||||
*
|
||||
* After calling this function, the XArray is empty and has freed all memory
|
||||
* allocated for its internal data structures. You are responsible for
|
||||
* freeing the objects referenced by the XArray.
|
||||
*
|
||||
* Context: Any context. Takes and releases the xa_lock, interrupt-safe.
|
||||
*/
|
||||
void xa_destroy(struct xarray *xa)
|
||||
{
|
||||
XA_STATE(xas, xa, 0);
|
||||
unsigned long flags;
|
||||
void *entry;
|
||||
|
||||
xas.xa_node = NULL;
|
||||
xas_lock_irqsave(&xas, flags);
|
||||
entry = xa_head_locked(xa);
|
||||
RCU_INIT_POINTER(xa->xa_head, NULL);
|
||||
xas_init_marks(&xas);
|
||||
/* lockdep checks we're still holding the lock in xas_free_nodes() */
|
||||
if (xa_is_node(entry))
|
||||
xas_free_nodes(&xas, xa_to_node(entry));
|
||||
xas_unlock_irqrestore(&xas, flags);
|
||||
}
|
||||
EXPORT_SYMBOL(xa_destroy);
|
||||
|
||||
#ifdef XA_DEBUG
|
||||
void xa_dump_node(const struct xa_node *node)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue