diff options
author | Ian Lance Taylor <ian@airs.com> | 2009-03-24 04:50:32 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2009-03-24 04:50:32 +0000 |
commit | 7f055c204a4371154123a1816fbec9855ee60ad5 (patch) | |
tree | 847b6ee09451800cc64d2f3fd933daf82f3a699b /gold/target-select.cc | |
parent | c39465150b2129c17f0a520d91dad23cc0632694 (diff) | |
download | fsf-binutils-gdb-7f055c204a4371154123a1816fbec9855ee60ad5.zip fsf-binutils-gdb-7f055c204a4371154123a1816fbec9855ee60ad5.tar.gz fsf-binutils-gdb-7f055c204a4371154123a1816fbec9855ee60ad5.tar.bz2 |
2009-03-23 Ian Lance Taylor <iant@google.com>
* gold-threads.h (class Initialize_lock): Define.
* gold-threads.cc (class Initialize_lock_once): Define.
(initialize_lock_control): New static variable.
(initialize_lock_pointer): New static variable.
(initialize_lock_once): New static function.
(Initialize_lock::Initialize_lock): Define.
(Initialize_lock::initialize): Define.
* target-select.h: Include "gold-threads.h".
(class Target_selector): Add lock_ and initialize_lock_ fields.
Don't define instantiate_target, just declare it.
* target-select.cc (Target_selector::Target_selector): Initialize
new fields.
(Target_selector::instantiate_target): Define.
* descriptors.h: Include "gold-threads.h".
(class Descriptors): Add initialize_lock_ field.
* descriptors.cc (Descriptors::Descriptors): Initialize new
field.
(Descriptors::open): Use initialize_lock_ field
* errors.h (class Errors): Add initialize_lock_ field.
* errors.cc (Errors::Errors): Initialize new field.
(Errors::initialize_lock): Use initialize_lock_ field.
* powerpc.cc (class Target_selector_powerpc): Remove
instantiated_target_ field. In do_recognize call
instantiate_target rather than do_instantiate_target. In
do_instantiate_target just allocate a new target.
* sparc.cc (class Target_selector_sparc): Likewise.
Diffstat (limited to 'gold/target-select.cc')
-rw-r--r-- | gold/target-select.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/gold/target-select.cc b/gold/target-select.cc index b81f5a2..55d63b2 100644 --- a/gold/target-select.cc +++ b/gold/target-select.cc @@ -46,13 +46,27 @@ namespace gold Target_selector::Target_selector(int machine, int size, bool is_big_endian, const char* bfd_name) : machine_(machine), size_(size), is_big_endian_(is_big_endian), - bfd_name_(bfd_name), instantiated_target_(NULL) + bfd_name_(bfd_name), instantiated_target_(NULL), lock_(NULL), + initialize_lock_(&this->lock_) { this->next_ = target_selectors; target_selectors = this; } +// Instantiate the target and return it. Use a lock to avoid +// instantiating two instances of the same target. + +Target* +Target_selector::instantiate_target() +{ + this->initialize_lock_.initialize(); + Hold_optional_lock hl(this->lock_); + if (this->instantiated_target_ == NULL) + this->instantiated_target_ = this->do_instantiate_target(); + return this->instantiated_target_; +} + // Find the target for an ELF file. Target* |