diff options
Diffstat (limited to 'lib/pvector.h')
-rw-r--r-- | lib/pvector.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/pvector.h b/lib/pvector.h index b175b213d..3d491ee25 100644 --- a/lib/pvector.h +++ b/lib/pvector.h @@ -62,8 +62,8 @@ struct pvector_entry { }; struct pvector_impl { - size_t size; /* Number of entries in the vector. */ - size_t allocated; /* Number of allocated entries. */ + atomic_size_t size; /* Number of entries in the vector. */ + size_t allocated; /* Number of allocated entries. */ struct pvector_entry vector[]; }; @@ -174,12 +174,17 @@ pvector_cursor_init(const struct pvector *pvec, { const struct pvector_impl *impl; struct pvector_cursor cursor; + size_t size; impl = ovsrcu_get(struct pvector_impl *, &pvec->impl); - ovs_prefetch_range(impl->vector, impl->size * sizeof impl->vector[0]); + /* Use memory_order_acquire to ensure entry access can not be + * reordered to happen before size read. */ + atomic_read_explicit(&CONST_CAST(struct pvector_impl *, impl)->size, + &size, memory_order_acquire); + ovs_prefetch_range(impl->vector, size * sizeof impl->vector[0]); - cursor.size = impl->size; + cursor.size = size; cursor.vector = impl->vector; cursor.entry_idx = -1; |