diff options
author | Ben Pfaff <blp@ovn.org> | 2017-08-30 09:33:14 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-08-31 07:49:38 -0700 |
commit | e4ef68817a8224404486a026df98495b6e0a86cd (patch) | |
tree | fee72063f6dfdfb3d6f6aa5e50820755bd5ede28 /ovsdb/monitor.c | |
parent | 5707b87db75c0d46cca47b9946c031600b95ded1 (diff) | |
download | openvswitch-e4ef68817a8224404486a026df98495b6e0a86cd.tar.gz |
monitor: Simplify calculation of cond->conditional.
This removes n_true_cnd from struct ovsdb_monitor_session_condition.
It was an "optimization" that is not part of any inner loop, but
make the code harder to reason about.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
Acked-by: Liran Schour <lirans@il.ibm.com>
Diffstat (limited to 'ovsdb/monitor.c')
-rw-r--r-- | ovsdb/monitor.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index 7a5c2f905..c0f9c557a 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -46,8 +46,7 @@ static struct hmap ovsdb_monitors = HMAP_INITIALIZER(&ovsdb_monitors); /* Keep state of session's conditions */ struct ovsdb_monitor_session_condition { - bool conditional; - size_t n_true_cnd; + bool conditional; /* True iff every table's condition is true. */ struct shash tables; /* Contains * "struct ovsdb_monitor_table_condition *"s. */ }; @@ -583,8 +582,17 @@ static inline void ovsdb_monitor_session_condition_set_mode( struct ovsdb_monitor_session_condition *cond) { - cond->conditional = shash_count(&cond->tables) != - cond->n_true_cnd; + struct shash_node *node; + + SHASH_FOR_EACH (node, &cond->tables) { + struct ovsdb_monitor_table_condition *mtc = node->data; + + if (!ovsdb_condition_is_true(&mtc->new_condition)) { + cond->conditional = true; + return; + } + } + cond->conditional = false; } /* Returnes an empty allocated session's condition state holder */ @@ -649,9 +657,6 @@ ovsdb_monitor_table_condition_create( shash_add(&condition->tables, table->schema->name, mtc); /* On session startup old == new condition */ ovsdb_condition_clone(&mtc->new_condition, &mtc->old_condition); - if (ovsdb_condition_is_true(&mtc->old_condition)) { - condition->n_true_cnd++; - } ovsdb_monitor_session_condition_set_mode(condition); return NULL; @@ -722,15 +727,6 @@ ovsdb_monitor_table_condition_updated(struct ovsdb_monitor_table *mt, /* If conditional monitoring - set old condition to new condition */ if (ovsdb_condition_cmp_3way(&mtc->old_condition, &mtc->new_condition)) { - if (ovsdb_condition_is_true(&mtc->new_condition)) { - if (!ovsdb_condition_is_true(&mtc->old_condition)) { - condition->n_true_cnd++; - } - } else { - if (ovsdb_condition_is_true(&mtc->old_condition)) { - condition->n_true_cnd--; - } - } ovsdb_condition_destroy(&mtc->old_condition); ovsdb_condition_clone(&mtc->old_condition, &mtc->new_condition); ovsdb_monitor_session_condition_set_mode(condition); |