From c067e5e08b14d5912f855b057481914b92610d83 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 12 Nov 2015 22:21:10 +1100 Subject: [PATCH] aga: Add aga_node_needs_update() internal function There are situations where aga algorithms may want to check if a node is up-to-date (i.e. has yet been discovered by the current algorithm) without making it up to date if it's not. This adds an internal function to do so. Signed-off-by: David Gibson --- ccan/aga/aga.c | 8 +++++++- ccan/aga/private.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ccan/aga/aga.c b/ccan/aga/aga.c index c1880ec5..c721b144 100644 --- a/ccan/aga/aga.c +++ b/ccan/aga/aga.c @@ -58,9 +58,15 @@ void aga_finish(struct aga_graph *g) g->sequence++; } +bool aga_node_needs_update(const struct aga_graph *g, + const struct aga_node *node) +{ + return (node->sequence != g->sequence); +} + bool aga_update_node(const struct aga_graph *g, struct aga_node *node) { - if (node->sequence == g->sequence) + if (!aga_node_needs_update(g, node)) return false; node->sequence = g->sequence; diff --git a/ccan/aga/private.h b/ccan/aga/private.h index ff9f1894..3095d3bc 100644 --- a/ccan/aga/private.h +++ b/ccan/aga/private.h @@ -3,6 +3,8 @@ #define CCAN_AGA_PRIVATE_H int aga_start(struct aga_graph *g); +bool aga_node_needs_update(const struct aga_graph *g, + const struct aga_node *node); bool aga_update_node(const struct aga_graph *g, struct aga_node *node); bool aga_check_state(const struct aga_graph *g); void aga_fail(struct aga_graph *g, int error); -- 2.39.2