cleanup: std::weak_ptr use: replace manual lock by std::weak_ptr::lock
The pattern
expired() ? shared_ptr<T>() : shared_ptr<T>(*this)
on std::weak_ptr<T> can be simplified by using std::weak_ptr<T>::lock.
Since weak_ptr::lock does this atomically, this patch also addresses
potential data races between the call to expired() and the construction
based on the assumption that the shared_ptr is still around.
Hence, apply this simplification/fix to the code base.
* src/abg-comparison-priv.h (diff::priv::get_context): improve
weak_ptr usage.
(corpus_diff:diff_stats::priv::ctxt): Likewise.
* src/abg-comparison.cc (corpus_diff::priv::get_context): Likewise.
(var_diff::type_diff): Likewise.
* src/abg-ir.cc (elf_symbol::get_next_alias): Likewise.
(elf_symbol::get_next_common_instance): Likewise.
(type_base::get_canonical_type): Likewise.
(qualified_type_def::get_underlying_type): Likewise.
(pointer_type_def::get_pointed_to_type): Likewise.
(reference_type_def::get_pointed_to_type): Likewise.
(array_type_def::subrange_type::get_underlying_type): Likewise.
(array_type_def::get_element_type): Likewise.
(typedef_decl::get_underlying_type): Likewise.
(var_decl::get_type): Likewise.
(function_type::get_return_type): Likewise.
(function_decl::get_type): Likewise.
(function_decl::parameter::get_type): Likewise.
(class_or_union::get_naming_typedef): Likewise.
(class_or_union::get_definition_of_declaration): Likewise.
(class_decl::base_spec::get_base_class): Likewise.
(template_parameter::get_enclosing_template_decl): Likewise.
(non_type_tparameter::get_type): Likewise.
(type_composition::get_composed_type): Likewise.
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
3 files changed