forked from Imagelibrary/binutils-gdb
Fix race in background index-cache writing
Tom de Vries pointed out a bug in the index-cache background writer -- sometimes it will fail. He also noted that it fails when the number of worker threads is set to zero. These turn out to be the same problem -- the cache can't be written to until the per-BFD's "index_table" member is set. This patch avoids the race by rearranging the code slightly, to ensure the cache cannot possibly be written before the member is set. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30261
This commit is contained in:
@@ -443,26 +443,32 @@ cooked_index_shard::wait (bool allow_quit) const
|
||||
m_future.wait ();
|
||||
}
|
||||
|
||||
cooked_index::cooked_index (vec_type &&vec, dwarf2_per_bfd *per_bfd)
|
||||
cooked_index::cooked_index (vec_type &&vec)
|
||||
: m_vector (std::move (vec))
|
||||
{
|
||||
for (auto &idx : m_vector)
|
||||
idx->finalize ();
|
||||
|
||||
/* This must be set after all the finalization tasks have been
|
||||
started, because it may call 'wait'. */
|
||||
m_write_future
|
||||
= gdb::thread_pool::g_thread_pool->post_task ([this, per_bfd] ()
|
||||
{
|
||||
maybe_write_index (per_bfd);
|
||||
});
|
||||
|
||||
/* ACTIVE_VECTORS is not locked, and this assert ensures that this
|
||||
will be caught if ever moved to the background. */
|
||||
gdb_assert (is_main_thread ());
|
||||
active_vectors.insert (this);
|
||||
}
|
||||
|
||||
/* See cooked-index.h. */
|
||||
|
||||
void
|
||||
cooked_index::start_writing_index (dwarf2_per_bfd *per_bfd)
|
||||
{
|
||||
/* This must be set after all the finalization tasks have been
|
||||
started, because it may call 'wait'. */
|
||||
m_write_future
|
||||
= gdb::thread_pool::g_thread_pool->post_task ([this, per_bfd] ()
|
||||
{
|
||||
maybe_write_index (per_bfd);
|
||||
});
|
||||
}
|
||||
|
||||
cooked_index::~cooked_index ()
|
||||
{
|
||||
/* The 'finalize' method may be run in a different thread. If
|
||||
|
||||
Reference in New Issue
Block a user