From 53c173d01ee97f2b33dc81b1ca77a1a16ad976e6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 30 Aug 2025 21:49:27 +0200 Subject: [PATCH] [consider merging] avoid a warning on writing cells/files in 'under_construction' mode when there is nothing to update --- src/db/db/dbLayout.cc | 10 ++++++++-- src/db/db/dbLayout.h | 8 ++++++++ src/db/db/dbWriter.cc | 2 +- src/db/db/gsiDeclDbLayout.cc | 7 +++++++ src/db/unit_tests/dbLayoutTests.cc | 4 ++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 1cc992459..bf2a84e0e 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -1780,7 +1780,7 @@ Layout::force_update () // NOTE: the assumption is that either one thread is writing or // multiple threads are reading. Hence, we do not need to lock hier_dirty() or bboxes_dirty(). // We still do double checking as another thread might do the update as well. - if (! hier_dirty () && ! bboxes_dirty ()) { + if (! update_needed ()) { return; } @@ -1829,10 +1829,16 @@ Layout::update () const } } +bool +Layout::update_needed () const +{ + return hier_dirty () || bboxes_dirty (); +} + void Layout::do_update () { - if (! hier_dirty () && ! bboxes_dirty ()) { + if (! update_needed ()) { return; } diff --git a/src/db/db/dbLayout.h b/src/db/db/dbLayout.h index 02b98a593..4c0d0078a 100644 --- a/src/db/db/dbLayout.h +++ b/src/db/db/dbLayout.h @@ -1619,6 +1619,14 @@ public: */ top_down_const_iterator end_top_cells () const; + /** + * @brief Gets a value indicating whether an update is needed + * + * If this value is false, update or force_update will not + * do anything. + */ + bool update_needed () const; + /** * @brief Provide a const version of the update method * diff --git a/src/db/db/dbWriter.cc b/src/db/db/dbWriter.cc index bab0f58dd..9cf4cfb9a 100644 --- a/src/db/db/dbWriter.cc +++ b/src/db/db/dbWriter.cc @@ -58,7 +58,7 @@ Writer::write (db::Layout &layout, tl::OutputStream &stream) { tl::SelfTimer timer (tl::verbosity () >= 21, tl::to_string (tr ("Writing file: ")) + stream.path ()); - if (layout.under_construction ()) { + if (layout.under_construction () && layout.update_needed ()) { tl::warn << tl::to_string (tr ("Cannot properly write a layout that is under construction - forcing update.")); layout.force_update (); } diff --git a/src/db/db/gsiDeclDbLayout.cc b/src/db/db/gsiDeclDbLayout.cc index 647dbd921..c222a74ac 100644 --- a/src/db/db/gsiDeclDbLayout.cc +++ b/src/db/db/gsiDeclDbLayout.cc @@ -1758,6 +1758,13 @@ Class decl_Layout ("db", "Layout", "is ongoing or the layout is brought into invalid state by\n" "\"start_changes\".\n" ) + + gsi::method ("update_needed", &db::Layout::update_needed, + "@brief Gets a value indicating whether the Layout object needs an update\n" + "If this method returns false, \\update will not do anything. This is useful to force an update at " + "specific times during 'under_construction' conditions.\n" + "\n" + "This method has been introduced in version 0.30.4." + ) + gsi::method ("update", (void (db::Layout::*) ()) &db::Layout::force_update, "@brief Updates the internals of the layout\n" "This method updates the internal state of the layout. Usually this is done automatically\n" diff --git a/src/db/unit_tests/dbLayoutTests.cc b/src/db/unit_tests/dbLayoutTests.cc index e96cb5c28..00fbb2056 100644 --- a/src/db/unit_tests/dbLayoutTests.cc +++ b/src/db/unit_tests/dbLayoutTests.cc @@ -294,7 +294,9 @@ TEST(2) EXPECT_EQ (g.hier_generation_id (), size_t (3)); g.clear (); + EXPECT_EQ (g.update_needed (), true); g.update (); + EXPECT_EQ (g.update_needed (), false); el.reset (); EXPECT_EQ (g.hier_generation_id (), size_t (4)); @@ -387,7 +389,9 @@ TEST(3) EXPECT_EQ (el.hier_dirty, true); el.reset (); + EXPECT_EQ (g.update_needed (), true); g.update (); + EXPECT_EQ (g.update_needed (), false); top->shapes (0).insert (db::Box (0, 0, 10, 20)); top->shapes (1).insert (db::Box (0, 0, 10, 20));