xarray: Add XArray conditional store operations
Like cmpxchg(), xa_cmpxchg will only store to the index if the current entry matches the old entry. It returns the current entry, which is usually more useful than the errno returned by radix_tree_insert(). For the users who really only want the errno, the xa_insert() wrapper provides a more convenient calling convention. Signed-off-by: Matthew Wilcox <willy@infradead.org>
This commit is contained in:
parent
58d6ea3085
commit
41aec91f55
3 changed files with 151 additions and 0 deletions
|
|
@ -198,6 +198,25 @@ static noinline void check_xa_shrink(struct xarray *xa)
|
|||
XA_BUG_ON(xa, !xa_empty(xa));
|
||||
}
|
||||
|
||||
static noinline void check_cmpxchg(struct xarray *xa)
|
||||
{
|
||||
void *FIVE = xa_mk_value(5);
|
||||
void *SIX = xa_mk_value(6);
|
||||
void *LOTS = xa_mk_value(12345678);
|
||||
|
||||
XA_BUG_ON(xa, !xa_empty(xa));
|
||||
XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL);
|
||||
XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EEXIST);
|
||||
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS);
|
||||
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS);
|
||||
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE);
|
||||
XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != NULL);
|
||||
XA_BUG_ON(xa, xa_cmpxchg(xa, 5, NULL, FIVE, GFP_KERNEL) != NULL);
|
||||
xa_erase_index(xa, 12345678);
|
||||
xa_erase_index(xa, 5);
|
||||
XA_BUG_ON(xa, !xa_empty(xa));
|
||||
}
|
||||
|
||||
static noinline void check_multi_store(struct xarray *xa)
|
||||
{
|
||||
#ifdef CONFIG_XARRAY_MULTI
|
||||
|
|
@ -274,6 +293,7 @@ static int xarray_checks(void)
|
|||
check_xa_load(&array);
|
||||
check_xa_mark(&array);
|
||||
check_xa_shrink(&array);
|
||||
check_cmpxchg(&array);
|
||||
check_multi_store(&array);
|
||||
|
||||
printk("XArray: %u of %u tests passed\n", tests_passed, tests_run);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue