]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/workqueue-internal.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gold / workqueue-internal.h
CommitLineData
c7912668
ILT
1// workqueue-internal.h -- internal work queue header for gold -*- C++ -*-
2
250d07de 3// Copyright (C) 2006-2021 Free Software Foundation, Inc.
c7912668
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
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.
12
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.
17
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.
22
23#ifndef GOLD_WORKQUEUE_INTERNAL_H
24#define GOLD_WORKQUEUE_INTERNAL_H
25
26#include <queue>
17a1d0a9 27#include <csignal>
c7912668
ILT
28
29#include "gold-threads.h"
30#include "workqueue.h"
31
32// This is an internal header file for different gold workqueue
33// implementations.
34
35namespace gold
36{
37
38class Workqueue_thread;
39
17a1d0a9
ILT
40// The Workqueue_threader abstract class. This is the interface used
41// by the general workqueue code to manage threads.
c7912668 42
17a1d0a9 43class Workqueue_threader
c7912668
ILT
44{
45 public:
17a1d0a9 46 Workqueue_threader(Workqueue* workqueue)
c7912668
ILT
47 : workqueue_(workqueue)
48 { }
17a1d0a9 49 virtual ~Workqueue_threader()
c7912668
ILT
50 { }
51
c7912668
ILT
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;
56
17a1d0a9
ILT
57 // Return whether to cancel the current thread.
58 virtual bool
dcd8d12e 59 should_cancel_thread(int thread_number) = 0;
c7912668 60
17a1d0a9
ILT
61 protected:
62 // Get the Workqueue.
63 Workqueue*
64 get_workqueue()
c7912668
ILT
65 { return this->workqueue_; }
66
67 private:
17a1d0a9 68 // The Workqueue.
c7912668
ILT
69 Workqueue* workqueue_;
70};
71
17a1d0a9 72// The threaded instantiation of Workqueue_threader.
c7912668 73
17a1d0a9 74class Workqueue_threader_threadpool : public Workqueue_threader
c7912668
ILT
75{
76 public:
17a1d0a9 77 Workqueue_threader_threadpool(Workqueue*);
c7912668 78
17a1d0a9 79 ~Workqueue_threader_threadpool();
c7912668 80
17a1d0a9 81 // Set the thread count.
c7912668
ILT
82 void
83 set_thread_count(int);
84
17a1d0a9 85 // Return whether to cancel a thread.
c7912668 86 bool
dcd8d12e 87 should_cancel_thread(int thread_number);
c7912668 88
17a1d0a9 89 // Process all tasks. This keeps running until told to cancel.
c7912668 90 void
17a1d0a9
ILT
91 process(int thread_number)
92 { this->get_workqueue()->process(thread_number); }
c7912668 93
17a1d0a9
ILT
94 private:
95 // This is set if we need to check the thread count.
96 volatile sig_atomic_t check_thread_count_;
c7912668 97
17a1d0a9 98 // Lock for the remaining members.
c7912668 99 Lock lock_;
17a1d0a9
ILT
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_;
c7912668
ILT
105};
106
107} // End namespace gold.
108
109#endif // !defined(GOLD_WORKQUEUE_INTERNAL_H)