[GAS][ARM] Fix UDF testism
[binutils-gdb.git] / gold / workqueue-internal.h
blob3cde16aa9cbe326dc8d7167463d6731a5a63da27
1 // workqueue-internal.h -- internal work queue header for gold -*- C++ -*-
3 // Copyright (C) 2006-2018 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 #ifndef GOLD_WORKQUEUE_INTERNAL_H
24 #define GOLD_WORKQUEUE_INTERNAL_H
26 #include <queue>
27 #include <csignal>
29 #include "gold-threads.h"
30 #include "workqueue.h"
32 // This is an internal header file for different gold workqueue
33 // implementations.
35 namespace gold
38 class Workqueue_thread;
40 // The Workqueue_threader abstract class. This is the interface used
41 // by the general workqueue code to manage threads.
43 class Workqueue_threader
45 public:
46 Workqueue_threader(Workqueue* workqueue)
47 : workqueue_(workqueue)
48 { }
49 virtual ~Workqueue_threader()
50 { }
52 // Set the number of threads to use. This is ignored when not using
53 // threads.
54 virtual void
55 set_thread_count(int) = 0;
57 // Return whether to cancel the current thread.
58 virtual bool
59 should_cancel_thread(int thread_number) = 0;
61 protected:
62 // Get the Workqueue.
63 Workqueue*
64 get_workqueue()
65 { return this->workqueue_; }
67 private:
68 // The Workqueue.
69 Workqueue* workqueue_;
72 // The threaded instantiation of Workqueue_threader.
74 class Workqueue_threader_threadpool : public Workqueue_threader
76 public:
77 Workqueue_threader_threadpool(Workqueue*);
79 ~Workqueue_threader_threadpool();
81 // Set the thread count.
82 void
83 set_thread_count(int);
85 // Return whether to cancel a thread.
86 bool
87 should_cancel_thread(int thread_number);
89 // Process all tasks. This keeps running until told to cancel.
90 void
91 process(int thread_number)
92 { this->get_workqueue()->process(thread_number); }
94 private:
95 // This is set if we need to check the thread count.
96 volatile sig_atomic_t check_thread_count_;
98 // Lock for the remaining members.
99 Lock lock_;
100 // The number of threads we want to create. This is set to zero
101 // when all threads should exit.
102 int desired_thread_count_;
103 // The number of threads currently running.
104 int threads_;
107 } // End namespace gold.
109 #endif // !defined(GOLD_WORKQUEUE_INTERNAL_H)