History

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.

Matthew Wilcox committed 9 years ago

Commit 41aec911 parent 58d6ea33 files · +151 −0Browse files

Showing the changes to lib/test_xarray.c (1 of 3 files). Show all

Unified · Split

lib/test_xarray.c+20−0
@@ -198,6 +198,25 @@ static noinline void check_xa_shrink(struct xarray *xa) · 197 unmodified lines
198198 XA_BUG_ON(xa, !xa_empty(xa));
199199 }
200200
201+static noinline void check_cmpxchg(struct xarray *xa)
202+{
203+ void *FIVE = xa_mk_value(5);
204+ void *SIX = xa_mk_value(6);
205+ void *LOTS = xa_mk_value(12345678);
206+
207+ XA_BUG_ON(xa, !xa_empty(xa));
208+ XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL);
209+ XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EEXIST);
210+ XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS);
211+ XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS);
212+ XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE);
213+ XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != NULL);
214+ XA_BUG_ON(xa, xa_cmpxchg(xa, 5, NULL, FIVE, GFP_KERNEL) != NULL);
215+ xa_erase_index(xa, 12345678);
216+ xa_erase_index(xa, 5);
217+ XA_BUG_ON(xa, !xa_empty(xa));
218+}
219+
201220 static noinline void check_multi_store(struct xarray *xa)
202221 {
203222 #ifdef CONFIG_XARRAY_MULTI
@@ -274,6 +293,7 @@ static int xarray_checks(void) · 70 unmodified lines
274293 check_xa_load(&array);
275294 check_xa_mark(&array);
276295 check_xa_shrink(&array);
296+ check_cmpxchg(&array);
277297 check_multi_store(&array);
278298
279299 printk("XArray: %u of %u tests passed\n", tests_passed, tests_run);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t