diff options
author | Ian Lance Taylor <iant@google.com> | 2007-10-17 06:24:50 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-10-17 06:24:50 +0000 |
commit | fe9a4c1201a3e0867cbc0324c55cfe90dce9415b (patch) | |
tree | 1cfc4aa11a0b71f31000b3fb7abecc367dd52180 /gold/workqueue.cc | |
parent | ae326da8ebcb14de70678bb726732a1c8923d63c (diff) | |
download | gdb-fe9a4c1201a3e0867cbc0324c55cfe90dce9415b.zip gdb-fe9a4c1201a3e0867cbc0324c55cfe90dce9415b.tar.gz gdb-fe9a4c1201a3e0867cbc0324c55cfe90dce9415b.tar.bz2 |
Add infrastructure for threading support.
Diffstat (limited to 'gold/workqueue.cc')
-rw-r--r-- | gold/workqueue.cc | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/gold/workqueue.cc b/gold/workqueue.cc index 2c7e880..95c14ce 100644 --- a/gold/workqueue.cc +++ b/gold/workqueue.cc @@ -22,6 +22,10 @@ #include "gold.h" +#ifdef ENABLE_THREADS +#include <pthread.h> +#endif + #include "workqueue.h" namespace gold @@ -153,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. @@ -178,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 @@ -188,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_(), @@ -199,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() @@ -421,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. |