// target-select.h -- select a target for an object file -*- C++ -*-
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
#include <vector>
+#include "gold-threads.h"
+
namespace gold
{
class Target;
+class Target_selector;
+
+// Used to set the target only once.
+
+class Set_target_once : public Once
+{
+ public:
+ Set_target_once(Target_selector* target_selector)
+ : target_selector_(target_selector)
+ { }
+
+ protected:
+ void
+ do_run_once(void*);
+
+ private:
+ Target_selector* target_selector_;
+};
// We want to avoid a master list of targets, which implies using a
// global constructor. And we also want the program to start up as
// Instantiate the target and return it.
Target*
- instantiate_target()
- {
- if (this->instantiated_target_ == NULL)
- this->instantiated_target_ = this->do_instantiate_target();
- return this->instantiated_target_;
- }
+ instantiate_target();
private:
+ // Set the target.
+ void
+ set_target();
+
+ friend class Set_target_once;
+
// ELF machine code.
const int machine_;
// Target size--32 or 64.
// The singleton Target structure--this points to an instance of the
// real implementation.
Target* instantiated_target_;
+ // Used to set the target only once.
+ Set_target_once set_target_once_;
};
// Select the target for an ELF file.