~ubuntu-branches/ubuntu/utopic/binutils-arm64-cross/utopic

« back to all changes in this revision

Viewing changes to binutils-2.23.52.20130611/gold/workqueue-internal.h

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-06-20 17:38:09 UTC
  • Revision ID: package-import@ubuntu.com-20130620173809-app8lzgvymy5fg6c
Tags: 0.7
Build-depend on binutils-source (>= 2.23.52.20130620-1~).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// workqueue-internal.h -- internal work queue header for gold   -*- C++ -*-
 
2
 
 
3
// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
 
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>
 
27
#include <csignal>
 
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
 
 
35
namespace gold
 
36
{
 
37
 
 
38
class Workqueue_thread;
 
39
 
 
40
// The Workqueue_threader abstract class.  This is the interface used
 
41
// by the general workqueue code to manage threads.
 
42
 
 
43
class Workqueue_threader
 
44
{
 
45
 public:
 
46
  Workqueue_threader(Workqueue* workqueue)
 
47
    : workqueue_(workqueue)
 
48
  { }
 
49
  virtual ~Workqueue_threader()
 
50
  { }
 
51
 
 
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
 
 
57
  // Return whether to cancel the current thread.
 
58
  virtual bool
 
59
  should_cancel_thread(int thread_number) = 0;
 
60
 
 
61
 protected:
 
62
  // Get the Workqueue.
 
63
  Workqueue*
 
64
  get_workqueue()
 
65
  { return this->workqueue_; }
 
66
 
 
67
 private:
 
68
  // The Workqueue.
 
69
  Workqueue* workqueue_;
 
70
};
 
71
 
 
72
// The threaded instantiation of Workqueue_threader.
 
73
 
 
74
class Workqueue_threader_threadpool : public Workqueue_threader
 
75
{
 
76
 public:
 
77
  Workqueue_threader_threadpool(Workqueue*);
 
78
 
 
79
  ~Workqueue_threader_threadpool();
 
80
 
 
81
  // Set the thread count.
 
82
  void
 
83
  set_thread_count(int);
 
84
 
 
85
  // Return whether to cancel a thread.
 
86
  bool
 
87
  should_cancel_thread(int thread_number);
 
88
 
 
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); }
 
93
 
 
94
 private:
 
95
  // This is set if we need to check the thread count.
 
96
  volatile sig_atomic_t check_thread_count_;
 
97
 
 
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_;
 
105
};
 
106
 
 
107
} // End namespace gold.
 
108
 
 
109
#endif // !defined(GOLD_WORKQUEUE_INTERNAL_H)