Default to --allow-shlib-undefined for now.
[deliverable/binutils-gdb.git] / gold / workqueue.cc
index 9062118aaa00d2b2f638f5993cfd5b12cecf8f39..95c14ce5a8594dd970fa35054f872c1dfb3bef4a 100644 (file)
@@ -1,7 +1,31 @@
 // workqueue.cc -- the workqueue for gold
 
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
 #include "gold.h"
 
+#ifdef ENABLE_THREADS
+#include <pthread.h>
+#endif
+
 #include "workqueue.h"
 
 namespace gold
@@ -133,7 +157,13 @@ class Workqueue_runner
   { }
 
   // Run a task.  This is always called in the main thread.
-  virtual void run(Task*, Task_locker*) = 0;
+  virtual void
+  run(Task*, Task_locker*) = 0;
+
+  // Set the number of threads to use.  This is ignored when not using
+  // threads.
+  virtual void
+  set_thread_count(int) = 0;
 
  protected:
   // This is called by an implementation when a task is completed.
@@ -158,7 +188,11 @@ class Workqueue_runner_single : public Workqueue_runner
   ~Workqueue_runner_single()
   { }
 
-  void run(Task*, Task_locker*);
+  void
+  run(Task*, Task_locker*);
+
+  void
+  set_thread_count(int);
 };
 
 void
@@ -168,9 +202,15 @@ Workqueue_runner_single::run(Task* t, Task_locker* tl)
   this->completed(t, tl);
 }
 
+void
+Workqueue_runner_single::set_thread_count(int thread_count)
+{
+  gold_assert(thread_count > 0);
+}
+
 // Workqueue methods.
 
-Workqueue::Workqueue(const General_options&)
+Workqueue::Workqueue(const General_options& options)
   : tasks_lock_(),
     tasks_(),
     completed_lock_(),
@@ -179,9 +219,14 @@ Workqueue::Workqueue(const General_options&)
     completed_condvar_(this->completed_lock_),
     cleared_blockers_(0)
 {
-  // At some point we will select the specific implementation of
-  // Workqueue_runner to use based on the command line options.
-  this->runner_ = new Workqueue_runner_single(this);
+  bool threads = options.threads();
+#ifndef ENABLE_THREADS
+  threads = false;
+#endif
+  if (!threads)
+    this->runner_ = new Workqueue_runner_single(this);
+  else
+    gold_unreachable();
 }
 
 Workqueue::~Workqueue()
@@ -401,4 +446,13 @@ Workqueue::cleared_blocker()
   ++this->cleared_blockers_;
 }
 
+// Set the number of threads to use for the workqueue, if we are using
+// threads.
+
+void
+Workqueue::set_thread_count(int threads)
+{
+  this->runner_->set_thread_count(threads);
+}
+
 } // End namespace gold.
This page took 0.023554 seconds and 4 git commands to generate.