summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>2020-04-17 20:42:41 +0300
committerDylan Baker <dylan@pnwbakers.com>2020-04-20 10:01:27 -0700
commiteb39c5fb4f8f30a203e20abd14f13c30fe28b8d8 (patch)
tree9e17dabbbe1b4c93eb2ac12e6d9b803850e9818d
parent29200718b5baa3d64e7caf6606a277cccaa3f01c (diff)
util/sparse_free_list: manipulate node pointers using atomic primitives
Probably doesn't fix anything but those should be accessed in an atomic way just like the head pointer. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Fixes: e4f01eca3b3cd1 ("util: Add a free list structure for use with util_sparse_array") Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4613> (cherry picked from commit cdc43775917e301a7ca654fcebb94fad08dc4131)
-rw-r--r--.pick_status.json2
-rw-r--r--src/util/sparse_array.c8
2 files changed, 5 insertions, 5 deletions
diff --git a/.pick_status.json b/.pick_status.json
index f89d75a2ef0..839d00f452c 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -238,7 +238,7 @@
"description": "util/sparse_free_list: manipulate node pointers using atomic primitives",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "e4f01eca3b3cd1701f21cacbb8d29fe688ba42bb"
},
diff --git a/src/util/sparse_array.c b/src/util/sparse_array.c
index 39420473420..4691adcc88d 100644
--- a/src/util/sparse_array.c
+++ b/src/util/sparse_array.c
@@ -220,7 +220,7 @@ util_sparse_array_free_list_push(struct util_sparse_array_free_list *fl,
void *last_elem = util_sparse_array_get(fl->arr, items[0]);
uint32_t *last_next = (uint32_t *)((char *)last_elem + fl->next_offset);
for (unsigned i = 1; i < num_items; i++) {
- *last_next = items[i];
+ p_atomic_set(last_next, items[i]);
assert(items[i] != fl->sentinel);
last_elem = util_sparse_array_get(fl->arr, items[i]);
last_next = (uint32_t *)((char *)last_elem + fl->next_offset);
@@ -230,7 +230,7 @@ util_sparse_array_free_list_push(struct util_sparse_array_free_list *fl,
old_head = p_atomic_read(&fl->head);
do {
current_head = old_head;
- *last_next = current_head; /* Index is the bottom 32 bits */
+ p_atomic_set(last_next, (uint32_t)current_head); /* Index is the bottom 32 bits */
uint64_t new_head = free_list_head(current_head, items[0]);
old_head = p_atomic_cmpxchg(&fl->head, current_head, new_head);
} while (old_head != current_head);
@@ -249,7 +249,7 @@ util_sparse_array_free_list_pop_idx(struct util_sparse_array_free_list *fl)
uint32_t head_idx = current_head; /* Index is the bottom 32 bits */
void *head_elem = util_sparse_array_get(fl->arr, head_idx);
uint32_t *head_next = (uint32_t *)((char *)head_elem + fl->next_offset);
- uint64_t new_head = free_list_head(current_head, *head_next);
+ uint64_t new_head = free_list_head(current_head, p_atomic_read(head_next));
uint64_t old_head = p_atomic_cmpxchg(&fl->head, current_head, new_head);
if (old_head == current_head)
return head_idx;
@@ -270,7 +270,7 @@ util_sparse_array_free_list_pop_elem(struct util_sparse_array_free_list *fl)
uint32_t head_idx = current_head; /* Index is the bottom 32 bits */
void *head_elem = util_sparse_array_get(fl->arr, head_idx);
uint32_t *head_next = (uint32_t *)((char *)head_elem + fl->next_offset);
- uint64_t new_head = free_list_head(current_head, *head_next);
+ uint64_t new_head = free_list_head(current_head, p_atomic_read(head_next));
uint64_t old_head = p_atomic_cmpxchg(&fl->head, current_head, new_head);
if (old_head == current_head)
return head_elem;