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