History

XArray: Add xa_for_each_range

This function supports iterating over a range of an array. Also add documentation links for xa_for_each_start().

Matthew Wilcox (Oracle) committed 6 years ago

Commit 00ed4521 parent c44aa5e2 files · +38 −9Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/xarray.h+32−5
@@ -416,6 +416,36 @@ static inline bool xa_marked(const struct xarray *xa, xa_mark_t mark) · 415 unmodified lines
416 return xa->xa_flags & XA_FLAGS_MARK(mark);416 return xa->xa_flags & XA_FLAGS_MARK(mark);
417}417}
418 418
419/**
420 * xa_for_each_range() - Iterate over a portion of an XArray.
421 * @xa: XArray.
422 * @index: Index of @entry.
423 * @entry: Entry retrieved from array.
424 * @start: First index to retrieve from array.
425 * @last: Last index to retrieve from array.
426 *
427 * During the iteration, @entry will have the value of the entry stored
428 * in @xa at @index. You may modify @index during the iteration if you
429 * want to skip or reprocess indices. It is safe to modify the array
430 * during the iteration. At the end of the iteration, @entry will be set
431 * to NULL and @index will have a value less than or equal to max.
432 *
433 * xa_for_each_range() is O(n.log(n)) while xas_for_each() is O(n). You have
434 * to handle your own locking with xas_for_each(), and if you have to unlock
435 * after each iteration, it will also end up being O(n.log(n)).
436 * xa_for_each_range() will spin if it hits a retry entry; if you intend to
437 * see retry entries, you should use the xas_for_each() iterator instead.
438 * The xas_for_each() iterator will expand into more inline code than
439 * xa_for_each_range().
440 *
441 * Context: Any context. Takes and releases the RCU lock.
442 */
443#define xa_for_each_range(xa, index, entry, start, last) \
444 for (index = start, \
445 entry = xa_find(xa, &index, last, XA_PRESENT); \
446 entry; \
447 entry = xa_find_after(xa, &index, last, XA_PRESENT))
448
419/**449/**
420 * xa_for_each_start() - Iterate over a portion of an XArray.450 * xa_for_each_start() - Iterate over a portion of an XArray.
421 * @xa: XArray.451 * @xa: XArray.
@@ -439,11 +469,8 @@ static inline bool xa_marked(const struct xarray *xa, xa_mark_t mark) · 17 unmodified lines
439 *469 *
440 * Context: Any context. Takes and releases the RCU lock.470 * Context: Any context. Takes and releases the RCU lock.
441 */471 */
442#define xa_for_each_start(xa, index, entry, start) \472#define xa_for_each_start(xa, index, entry, start) \
443 for (index = start, \473 xa_for_each_range(xa, index, entry, start, ULONG_MAX)
444 entry = xa_find(xa, &index, ULONG_MAX, XA_PRESENT); \
445 entry; \
446 entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT))
447 474
448/**475/**
449 * xa_for_each() - Iterate over present entries in an XArray.476 * xa_for_each() - Iterate over present entries in an XArray.