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