]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Clean up cooked_index::done_reading
authorTom Tromey <tom@tromey.com>
Fri, 28 Mar 2025 16:26:36 +0000 (10:26 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 2 Apr 2025 21:50:04 +0000 (15:50 -0600)
The cooked index worker maintains the state for the various state
transition in the scanner.  It is held by the cooked_index while
scanning is in progress, then deleted once this has completed.

I noticed that none of the arguments to cooked_index::done_reading
were really needed -- the cooked_index already has access to the
worker should it need it.  Removing these parameters makes the code a
bit simpler and also cleans up some confusing code around the use of
the deferred warnings object.

Regression tested on x86-64 Fedora 40.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/cooked-index-worker.c
gdb/dwarf2/cooked-index-worker.h
gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h

index 95ec9436c17b02c84d945b07148eab2af9f84594..da51a8c72e81c31e04751840735d90a14cbfbe4e 100644 (file)
@@ -226,8 +226,7 @@ cooked_index_worker::set (cooked_state desired_state)
 /* See cooked-index-worker.h.  */
 
 void
-cooked_index_worker::write_to_cache (const cooked_index *idx,
-                                    deferred_warnings *warn) const
+cooked_index_worker::write_to_cache (const cooked_index *idx)
 {
   if (idx != nullptr)
     {
@@ -235,7 +234,7 @@ cooked_index_worker::write_to_cache (const cooked_index *idx,
         See PR symtab/30837.  This arranges to capture all such
         warnings.  This is safe because we know the deferred_warnings
         object isn't in use by any other thread at this point.  */
-      scoped_restore_warning_hook defer (warn);
+      scoped_restore_warning_hook defer (&m_warnings);
       m_cache_store.store ();
     }
 }
@@ -245,21 +244,12 @@ cooked_index_worker::write_to_cache (const cooked_index *idx,
 void
 cooked_index_worker::done_reading ()
 {
-  /* Only handle the scanning results here.  Complaints and exceptions
-     can only be dealt with on the main thread.  */
-  std::vector<cooked_index_shard_up> shards;
-
   for (auto &one_result : m_results)
-    {
-      shards.push_back (one_result.release_shard ());
-      m_all_parents_map.add_map (*one_result.get_parent_map ());
-    }
-
-  shards.shrink_to_fit ();
+    m_all_parents_map.add_map (*one_result.get_parent_map ());
 
   dwarf2_per_bfd *per_bfd = m_per_objfile->per_bfd;
   cooked_index *table
     = (gdb::checked_static_cast<cooked_index *>
        (per_bfd->index_table.get ()));
-  table->set_contents (std::move (shards), &m_warnings, &m_all_parents_map);
+  table->set_contents ();
 }
index fbbb3b50905dbb513e2260b944ece5c5452ae6e2..df5c31d572dfe89c067c1118d34e7d07e8a084aa 100644 (file)
@@ -224,6 +224,22 @@ public:
      cache writer.)  */
   bool wait (cooked_state desired_state, bool allow_quit);
 
+  /* Release all shards from the results.  */
+  std::vector<cooked_index_shard_up> release_shards ()
+  {
+    std::vector<cooked_index_shard_up> result;
+    for (auto &one_result : m_results)
+      result.push_back (one_result.release_shard ());
+    result.shrink_to_fit ();
+    return result;
+  }
+
+  /* Return the object holding all the parent maps.  */
+  const parent_map_map *get_parent_map_map () const
+  {
+    return &m_all_parents_map;
+  }
+
 protected:
 
   /* Let cooked_index call the 'set' and 'write_to_cache' methods.  */
@@ -233,8 +249,7 @@ protected:
   void set (cooked_state desired_state);
 
   /* Write to the index cache.  */
-  void write_to_cache (const cooked_index *idx,
-                      deferred_warnings *warn) const;
+  void write_to_cache (const cooked_index *idx);
 
   /* Helper function that does the work of reading.  This must be able
      to be run in a worker thread without problems.  */
index 7a32a279cdb4e0c9681440afe0a4ded68c9c75cf..0f20b07f90cd508524e3f283182c5f5afc3c9038 100644 (file)
@@ -78,12 +78,10 @@ cooked_index::wait (cooked_state desired_state, bool allow_quit)
 }
 
 void
-cooked_index::set_contents (std::vector<cooked_index_shard_up> &&shards,
-                           deferred_warnings *warn,
-                           const parent_map_map *parent_maps)
+cooked_index::set_contents ()
 {
   gdb_assert (m_shards.empty ());
-  m_shards = std::move (shards);
+  m_shards = m_state->release_shards ();
 
   m_state->set (cooked_state::MAIN_AVAILABLE);
 
@@ -92,16 +90,17 @@ cooked_index::set_contents (std::vector<cooked_index_shard_up> &&shards,
      finalization.  However, that would take a slot in the global
      thread pool, and if enough such tasks were submitted at once, it
      would cause a livelock.  */
-  gdb::task_group finalizers ([this, warn] ()
+  gdb::task_group finalizers ([this] ()
   {
     m_state->set (cooked_state::FINALIZED);
-    m_state->write_to_cache (index_for_writing (), warn);
+    m_state->write_to_cache (index_for_writing ());
     m_state->set (cooked_state::CACHE_DONE);
   });
 
   for (auto &shard : m_shards)
     {
       auto this_shard = shard.get ();
+      const parent_map_map *parent_maps = m_state->get_parent_map_map ();
       finalizers.add_task ([=] () { this_shard->finalize (parent_maps); });
     }
 
index 583fa30004309fc1dd3aa3ca089d94613445b036..384938e5402dfa91908dfd28655bc9b1974a1051 100644 (file)
@@ -105,14 +105,8 @@ public:
   void start_reading () override;
 
   /* Called by cooked_index_worker to set the contents of this index
-     and transition to the MAIN_AVAILABLE state.  WARN is used to
-     collect any warnings that may arise when writing to the cache.
-     PARENT_MAPS is used when resolving pending parent links.
-     PARENT_MAPS may be NULL if there are no IS_PARENT_DEFERRED
-     entries in VEC.  */
-  void set_contents (std::vector<cooked_index_shard_up> &&vec,
-                    deferred_warnings *warn,
-                    const parent_map_map *parent_maps);
+     and transition to the MAIN_AVAILABLE state.  */
+  void set_contents ();
 
   /* A range over a vector of subranges.  */
   using range = range_chain<cooked_index_shard::range>;