diff mbox series

[ovs-dev,v2,2/3] parallel-hmap: rewrite iterator using multivar helpers

Message ID 20220420055537.445495-3-amorenoz@redhat.com
State Accepted
Headers show
Series Use newest OVS version to fix Undefined Behavior | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success

Commit Message

Adrián Moreno April 20, 2022, 5:55 a.m. UTC
Rewrite the parallel hmap iterator macros using multivariable iterator
helpers to avoid undefined behavior.

Suggested-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 lib/ovn-parallel-hmap.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Dumitru Ceara April 20, 2022, 8:18 a.m. UTC | #1
On 4/20/22 07:55, Adrian Moreno wrote:
> Rewrite the parallel hmap iterator macros using multivariable iterator
> helpers to avoid undefined behavior.
> 
> Suggested-by: Dumitru Ceara <dceara@redhat.com>
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---

Looks good to me, thanks!

Acked-by: Dumitru Ceara <dceara@redhat.com>
diff mbox series

Patch

diff --git a/lib/ovn-parallel-hmap.h b/lib/ovn-parallel-hmap.h
index 897208ef8..0f7d68770 100644
--- a/lib/ovn-parallel-hmap.h
+++ b/lib/ovn-parallel-hmap.h
@@ -58,11 +58,11 @@  extern "C" {
  * ThreadID + step * i as the JOBID parameter.
  */
 
-#define HMAP_FOR_EACH_IN_PARALLEL(NODE, MEMBER, JOBID, HMAP) \
-   for (INIT_CONTAINER(NODE, hmap_first_in_bucket_num(HMAP, JOBID), MEMBER); \
-        (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \
-       || ((NODE = NULL), false); \
-       ASSIGN_CONTAINER(NODE, hmap_next_in_bucket(&(NODE)->MEMBER), MEMBER))
+#define HMAP_FOR_EACH_IN_PARALLEL(NODE, MEMBER, JOBID, HMAP)                \
+   for (INIT_MULTIVAR(NODE, MEMBER, hmap_first_in_bucket_num(HMAP, JOBID),  \
+                      struct hmap_node);                                    \
+        CONDITION_MULTIVAR(NODE, MEMBER, ITER_VAR(NODE) != NULL);           \
+        UPDATE_MULTIVAR(NODE, hmap_next_in_bucket(ITER_VAR(NODE))))
 
 /* We do not have a SAFE version of the macro, because the hash size is not
  * atomic and hash removal operations would need to be wrapped with