forked from Imagelibrary/binutils-gdb
Clean up cooked_index::done_reading
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>
This commit is contained in:
@@ -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 ();
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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); });
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user