From a00647acd3b1c08c61234af994c2c29735a9b3ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Mar 2020 05:46:06 +0200 Subject: Add ability to query whether target has been matched for action --- libbuild2/target.hxx | 12 +++++++++--- libbuild2/target.ixx | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx index 1abda2d..ea72925 100644 --- a/libbuild2/target.hxx +++ b/libbuild2/target.hxx @@ -592,7 +592,13 @@ namespace build2 opstate& operator[] (action a) {return state[a];} const opstate& operator[] (action a) const {return state[a];} - // This function should only be called during match if we have observed + // Return true if the target has been matched for the specified action. + // This function can only be called during execution. + // + bool + matched (action) const; + + // This function can only be called during match if we have observed // (synchronization-wise) that this target has been matched (i.e., the // rule has been applied) for this action. // @@ -610,8 +616,8 @@ namespace build2 bool unchanged (action) const; - // This function should only be called during execution if we have - // observed (synchronization-wise) that this target has been executed. + // This function can only be called during execution if we have observed + // (synchronization-wise) that this target has been executed. // target_state executed_state (action, bool fail = true) const; diff --git a/libbuild2/target.ixx b/libbuild2/target.ixx index f7896d0..3842c37 100644 --- a/libbuild2/target.ixx +++ b/libbuild2/target.ixx @@ -66,6 +66,22 @@ namespace build2 } inline bool target:: + matched (action a) const + { + assert (ctx.phase == run_phase::execute); + + const opstate& s (state[a]); + + // Note that while the target could be being executed, we should see at + // least offset_matched since it must have been "achieved" before the + // phase switch. + // + size_t c (s.task_count.load (memory_order_relaxed) - ctx.count_base ()); + + return c >= offset_matched; + } + + inline bool target:: group_state (action a) const { // We go an extra step and short-circuit to the target state even if the @@ -96,6 +112,7 @@ namespace build2 const opstate& s (state[a]); // Note: already synchronized. + // size_t o (s.task_count.load (memory_order_relaxed) - ctx.count_base ()); if (o == offset_tried) -- cgit v1.1