* i386-linux-tdep.c (I386_LINUX_RECORD_SIZE_*,
[deliverable/binutils-gdb.git] / gold / target-select.cc
index b81f5a28ea8e38ebc2d180b3a8b1c37e43993d69..dcd3017f07c31694d77b9a77589b7120ab858ce8 100644 (file)
@@ -46,13 +46,32 @@ 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()
+{
+  // We assume that the pointer will either be written entirely or not
+  // at all.
+  if (this->instantiated_target_ == NULL)
+    {
+      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*
This page took 0.023291 seconds and 4 git commands to generate.