This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold patch committed: Only lock target selector if necessary
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Tue, 24 Mar 2009 10:33:54 -0700
- Subject: gold patch committed: Only lock target selector if necessary
I committed this patch to gold. This tweaks yesterday's patch to only
lock the target selector if necessary, avoiding a bunch of lock calls in
a large link.
I also committed a comment fix, without a ChangeLog entry.
Ian
2009-03-24 Ian Lance Taylor <iant@google.com>
* target-select.cc (instantiate_target): Don't acquire the lock if
the instantiated_target_ field has already been set.
Index: gold-threads.cc
===================================================================
RCS file: /cvs/src/src/gold/gold-threads.cc,v
retrieving revision 1.8
diff -u -p -r1.8 gold-threads.cc
--- gold-threads.cc 24 Mar 2009 04:50:32 -0000 1.8
+++ gold-threads.cc 24 Mar 2009 17:32:24 -0000
@@ -308,7 +308,7 @@ class Initialize_lock_once
static pthread_mutex_t initialize_lock_control = PTHREAD_MUTEX_INITIALIZER;
// A pointer to a pointer to the lock which we need to initialize
-// once. Access to this is controlled by initialize_lock_pointer.
+// once. Access to this is controlled by initialize_lock_control.
static Lock** initialize_lock_pointer;
Index: target-select.cc
===================================================================
RCS file: /cvs/src/src/gold/target-select.cc,v
retrieving revision 1.9
diff -u -p -r1.9 target-select.cc
--- target-select.cc 24 Mar 2009 04:50:32 -0000 1.9
+++ target-select.cc 24 Mar 2009 17:32:24 -0000
@@ -60,10 +60,15 @@ Target_selector::Target_selector(int mac
Target*
Target_selector::instantiate_target()
{
- this->initialize_lock_.initialize();
- Hold_optional_lock hl(this->lock_);
+ // We assume that the pointer will either be written entirely or not
+ // at all.
if (this->instantiated_target_ == NULL)
- this->instantiated_target_ = this->do_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_;
}