2007-11-22 01:05:51 +01:00
|
|
|
// workqueue-internal.h -- internal work queue header for gold -*- C++ -*-
|
|
|
|
|
2018-01-03 06:17:27 +01:00
|
|
|
// Copyright (C) 2006-2018 Free Software Foundation, Inc.
|
2007-11-22 01:05:51 +01:00
|
|
|
// Written by Ian Lance Taylor <iant@google.com>.
|
|
|
|
|
|
|
|
// This file is part of gold.
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
// MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef GOLD_WORKQUEUE_INTERNAL_H
|
|
|
|
#define GOLD_WORKQUEUE_INTERNAL_H
|
|
|
|
|
|
|
|
#include <queue>
|
2007-12-14 20:00:21 +01:00
|
|
|
#include <csignal>
|
2007-11-22 01:05:51 +01:00
|
|
|
|
|
|
|
#include "gold-threads.h"
|
|
|
|
#include "workqueue.h"
|
|
|
|
|
|
|
|
// This is an internal header file for different gold workqueue
|
|
|
|
// implementations.
|
|
|
|
|
|
|
|
namespace gold
|
|
|
|
{
|
|
|
|
|
|
|
|
class Workqueue_thread;
|
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// The Workqueue_threader abstract class. This is the interface used
|
|
|
|
// by the general workqueue code to manage threads.
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
class Workqueue_threader
|
2007-11-22 01:05:51 +01:00
|
|
|
{
|
|
|
|
public:
|
2007-12-14 20:00:21 +01:00
|
|
|
Workqueue_threader(Workqueue* workqueue)
|
2007-11-22 01:05:51 +01:00
|
|
|
: workqueue_(workqueue)
|
|
|
|
{ }
|
2007-12-14 20:00:21 +01:00
|
|
|
virtual ~Workqueue_threader()
|
2007-11-22 01:05:51 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
// Set the number of threads to use. This is ignored when not using
|
|
|
|
// threads.
|
|
|
|
virtual void
|
|
|
|
set_thread_count(int) = 0;
|
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// Return whether to cancel the current thread.
|
|
|
|
virtual bool
|
2011-07-29 01:25:06 +02:00
|
|
|
should_cancel_thread(int thread_number) = 0;
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
protected:
|
|
|
|
// Get the Workqueue.
|
|
|
|
Workqueue*
|
|
|
|
get_workqueue()
|
2007-11-22 01:05:51 +01:00
|
|
|
{ return this->workqueue_; }
|
|
|
|
|
|
|
|
private:
|
2007-12-14 20:00:21 +01:00
|
|
|
// The Workqueue.
|
2007-11-22 01:05:51 +01:00
|
|
|
Workqueue* workqueue_;
|
|
|
|
};
|
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// The threaded instantiation of Workqueue_threader.
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
class Workqueue_threader_threadpool : public Workqueue_threader
|
2007-11-22 01:05:51 +01:00
|
|
|
{
|
|
|
|
public:
|
2007-12-14 20:00:21 +01:00
|
|
|
Workqueue_threader_threadpool(Workqueue*);
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
~Workqueue_threader_threadpool();
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// Set the thread count.
|
2007-11-22 01:05:51 +01:00
|
|
|
void
|
|
|
|
set_thread_count(int);
|
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// Return whether to cancel a thread.
|
2007-11-22 01:05:51 +01:00
|
|
|
bool
|
2011-07-29 01:25:06 +02:00
|
|
|
should_cancel_thread(int thread_number);
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// Process all tasks. This keeps running until told to cancel.
|
2007-11-22 01:05:51 +01:00
|
|
|
void
|
2007-12-14 20:00:21 +01:00
|
|
|
process(int thread_number)
|
|
|
|
{ this->get_workqueue()->process(thread_number); }
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
private:
|
|
|
|
// This is set if we need to check the thread count.
|
|
|
|
volatile sig_atomic_t check_thread_count_;
|
2007-11-22 01:05:51 +01:00
|
|
|
|
2007-12-14 20:00:21 +01:00
|
|
|
// Lock for the remaining members.
|
2007-11-22 01:05:51 +01:00
|
|
|
Lock lock_;
|
2007-12-14 20:00:21 +01:00
|
|
|
// 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_;
|
2007-11-22 01:05:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace gold.
|
|
|
|
|
|
|
|
#endif // !defined(GOLD_WORKQUEUE_INTERNAL_H)
|