// 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
{ }
// 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.
~Workqueue_runner_single()
{ }
- void run(Task*, Task_locker*);
+ void
+ run(Task*, Task_locker*);
+
+ void
+ set_thread_count(int);
};
void
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_(),
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()
++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.