xarray.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * XArray implementation
  4. * Copyright (c) 2017 Microsoft Corporation
  5. * Author: Matthew Wilcox <willy@infradead.org>
  6. */
  7. #include <linux/export.h>
  8. #include <linux/xarray.h>
  9. /*
  10. * Coding conventions in this file:
  11. *
  12. * @xa is used to refer to the entire xarray.
  13. * @xas is the 'xarray operation state'. It may be either a pointer to
  14. * an xa_state, or an xa_state stored on the stack. This is an unfortunate
  15. * ambiguity.
  16. * @index is the index of the entry being operated on
  17. * @mark is an xa_mark_t; a small number indicating one of the mark bits.
  18. * @node refers to an xa_node; usually the primary one being operated on by
  19. * this function.
  20. * @offset is the index into the slots array inside an xa_node.
  21. * @parent refers to the @xa_node closer to the head than @node.
  22. * @entry refers to something stored in a slot in the xarray
  23. */
  24. /**
  25. * xa_init_flags() - Initialise an empty XArray with flags.
  26. * @xa: XArray.
  27. * @flags: XA_FLAG values.
  28. *
  29. * If you need to initialise an XArray with special flags (eg you need
  30. * to take the lock from interrupt context), use this function instead
  31. * of xa_init().
  32. *
  33. * Context: Any context.
  34. */
  35. void xa_init_flags(struct xarray *xa, gfp_t flags)
  36. {
  37. spin_lock_init(&xa->xa_lock);
  38. xa->xa_flags = flags;
  39. xa->xa_head = NULL;
  40. }
  41. EXPORT_SYMBOL(xa_init_flags);