From 6293ede7a742866a713050737cc2b43d51161b6f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 16 Feb 2018 16:24:07 +0200 Subject: Add support for detecting dependency cycles --- build2/diagnostics.hxx | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'build2/diagnostics.hxx') diff --git a/build2/diagnostics.hxx b/build2/diagnostics.hxx index 653d9a6..b9757d6 100644 --- a/build2/diagnostics.hxx +++ b/build2/diagnostics.hxx @@ -160,13 +160,37 @@ namespace build2 { explicit diag_frame (void (*f) (const diag_frame&, const diag_record&)) - : func_ (f), prev_ (stack) {stack = this;} + : func_ (f) + { + if (func_ != nullptr) + { + prev_ = stack; + stack = this; + } + } - // Start with an existing stack, for example, from another thread. - // - explicit - diag_frame (const diag_frame* prev) - : prev_ (stack) {stack = prev;} // Just a restore guard. + diag_frame (diag_frame&& x) + : func_ (x.func_) + { + if (func_ != nullptr) + { + prev_ = x.prev_; + stack = this; + + x.func_ = nullptr; + } + } + + diag_frame& operator= (diag_frame&&) = delete; + + diag_frame (const diag_frame&) = delete; + diag_frame& operator= (const diag_frame&) = delete; + + ~diag_frame () + { + if (func_ != nullptr ) + stack = prev_; + } static void apply (const diag_record& r) @@ -175,8 +199,6 @@ namespace build2 f->func_ (*f, r); } - ~diag_frame () {stack = prev_;} - static #ifdef __cpp_thread_local thread_local @@ -185,6 +207,13 @@ namespace build2 #endif const diag_frame* stack; // Tip of the stack. + struct stack_guard + { + explicit stack_guard (const diag_frame* s): s_ (stack) {stack = s;} + ~stack_guard () {stack = s_;} + const diag_frame* s_; + }; + private: void (*func_) (const diag_frame&, const diag_record&); const diag_frame* prev_; -- cgit v1.1