diff options
author | Ian Lance Taylor <iant@google.com> | 2007-12-14 19:00:21 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-12-14 19:00:21 +0000 |
commit | 17a1d0a9b26ce8f4f71073c41483baa0c10ed83b (patch) | |
tree | 3cdd95751145e2cf1cbcaedee2df8790c86b935d /gold/workqueue-internal.h | |
parent | 7004837e8d2e02ee35c50d236681e9c30a283619 (diff) | |
download | gdb-17a1d0a9b26ce8f4f71073c41483baa0c10ed83b.zip gdb-17a1d0a9b26ce8f4f71073c41483baa0c10ed83b.tar.gz gdb-17a1d0a9b26ce8f4f71073c41483baa0c10ed83b.tar.bz2 |
Rewrite workqueue. This version eliminates the master thread, and
reduces the amount of locking required to find a new thread to run.
Diffstat (limited to 'gold/workqueue-internal.h')
-rw-r--r-- | gold/workqueue-internal.h | 86 |
1 files changed, 33 insertions, 53 deletions
diff --git a/gold/workqueue-internal.h b/gold/workqueue-internal.h index d9fd160..201caa4 100644 --- a/gold/workqueue-internal.h +++ b/gold/workqueue-internal.h @@ -24,6 +24,7 @@ #define GOLD_WORKQUEUE_INTERNAL_H #include <queue> +#include <csignal> #include "gold-threads.h" #include "workqueue.h" @@ -36,92 +37,71 @@ namespace gold class Workqueue_thread; -// The Workqueue_runner abstract class. This is the interface used by -// the general workqueue code to actually run a task. +// The Workqueue_threader abstract class. This is the interface used +// by the general workqueue code to manage threads. -class Workqueue_runner +class Workqueue_threader { public: - Workqueue_runner(Workqueue* workqueue) + Workqueue_threader(Workqueue* workqueue) : workqueue_(workqueue) { } - virtual ~Workqueue_runner() + virtual ~Workqueue_threader() { } - // Run a task. This is always called in the main thread. - 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. - void completed(Task* t, Task_locker* tl) - { this->workqueue_->completed(t, tl); } + // Return whether to cancel the current thread. + virtual bool + should_cancel_thread() = 0; - Workqueue* get_workqueue() const + protected: + // Get the Workqueue. + Workqueue* + get_workqueue() { return this->workqueue_; } private: + // The Workqueue. Workqueue* workqueue_; }; -// The threaded instantiation of Workqueue_runner. +// The threaded instantiation of Workqueue_threader. -class Workqueue_runner_threadpool : public Workqueue_runner +class Workqueue_threader_threadpool : public Workqueue_threader { public: - Workqueue_runner_threadpool(Workqueue* workqueue); + Workqueue_threader_threadpool(Workqueue*); - ~Workqueue_runner_threadpool(); - - void - run(Task*, Task_locker*); + ~Workqueue_threader_threadpool(); + // Set the thread count. void set_thread_count(int); - private: - // This class can not be copied. - Workqueue_runner_threadpool(const Workqueue_runner_threadpool&); - Workqueue_runner_threadpool& operator=(const Workqueue_runner_threadpool&); - - // Return the next Task and Task_locker to run. This returns false - // if the calling thread should simply exit. + // Return whether to cancel a thread. bool - get_next(Task**, Task_locker**); + should_cancel_thread(); - // This is called when the thread completes a task. + // Process all tasks. This keeps running until told to cancel. void - thread_completed(Task*, Task_locker*); - - // The Workqueue_thread class calls functions from this and from the - // parent Workqueue_runner. - friend class Workqueue_thread; - - // An entry on the queue of tasks to run. - typedef std::pair<Task*, Task_locker*> Task_queue_entry; + process(int thread_number) + { this->get_workqueue()->process(thread_number); } - // A queue of tasks to run. - typedef std::queue<Task_queue_entry> Task_queue; + private: + // This is set if we need to check the thread count. + volatile sig_atomic_t check_thread_count_; - // The number of threads we want to create. This is only changed in - // the main thread or when only one thread is running. This is set - // to zero when all threads should exit. - int desired_thread_count_; - // A lock controlling access to the remaining fields. + // Lock for the remaining members. Lock lock_; - // The number of threads we have created. - int actual_thread_count_; - // The number of threads which are running a task. - int running_thread_count_; - // A queue of tasks to run. - Task_queue task_queue_; - // A condition variable which signals when the task_queue_ changed. - Condvar task_queue_condvar_; + // The number of threads we want to create. This is set to zero + // when all threads should exit. + int desired_thread_count_; + // The number of threads currently running. + int threads_; }; } // End namespace gold. |