old-cross-binutils/gold/workqueue.h

296 lines
7.4 KiB
C
Raw Normal View History

2006-08-04 23:10:59 +00:00
// workqueue.h -- the work queue for gold -*- C++ -*-
2014-03-05 11:46:15 +00:00
// Copyright (C) 2006-2014 Free Software Foundation, Inc.
// 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.
2006-08-04 23:10:59 +00:00
// After processing the command line, everything the linker does is
// driven from a work queue. This permits us to parallelize the
// linker where possible.
#ifndef GOLD_WORKQUEUE_H
#define GOLD_WORKQUEUE_H
#include <string>
2006-08-04 23:10:59 +00:00
#include "gold-threads.h"
#include "token.h"
2006-08-04 23:10:59 +00:00
namespace gold
{
class General_options;
2006-08-04 23:10:59 +00:00
class Workqueue;
// The superclass for tasks to be placed on the workqueue. Each
// specific task class will inherit from this one.
class Task
{
public:
Task()
: list_next_(NULL), name_(), should_run_soon_(false)
2006-08-04 23:10:59 +00:00
{ }
virtual ~Task()
{ }
// Check whether the Task can be run now. This method is only
// called with the workqueue lock held. If the Task can run, this
// returns NULL. Otherwise it returns a pointer to a token which
// must be released before the Task can run.
virtual Task_token*
is_runnable() = 0;
// Lock all the resources required by the Task, and store the locks
// in a Task_locker. This method does not need to do anything if no
// locks are required. This method is only called with the
// workqueue lock held.
virtual void
locks(Task_locker*) = 0;
2006-08-04 23:10:59 +00:00
// Run the task.
virtual void
run(Workqueue*) = 0;
// Return whether this task should run soon.
bool
should_run_soon() const
{ return this->should_run_soon_; }
// Note that this task should run soon.
void
set_should_run_soon()
{ this->should_run_soon_ = true; }
// Get the next Task on the list of Tasks. Called by Task_list.
Task*
list_next() const
{ return this->list_next_; }
// Set the next Task on the list of Tasks. Called by Task_list.
void
set_list_next(Task* t)
{
gold_assert(this->list_next_ == NULL);
this->list_next_ = t;
}
// Clear the next Task on the list of Tasks. Called by Task_list.
void
clear_list_next()
{ this->list_next_ = NULL; }
2007-11-22 00:05:51 +00:00
// Return the name of the Task. This is only used for debugging
// purposes.
const std::string&
name()
{
if (this->name_.empty())
this->name_ = this->get_name();
return this->name_;
}
protected:
// Get the name of the task. This must be implemented by the child
// class.
virtual std::string
get_name() const = 0;
private:
// Tasks may not be copied.
Task(const Task&);
Task& operator=(const Task&);
2007-11-22 00:05:51 +00:00
// If this Task is on a list, this is a pointer to the next Task on
// the list. We use this simple list structure rather than building
// a container, in order to avoid memory allocation while holding
// the Workqueue lock.
Task* list_next_;
2007-11-22 00:05:51 +00:00
// Task name, for debugging purposes.
std::string name_;
// Whether this Task should be executed soon. This is used for
// Tasks which can be run after some data is read.
bool should_run_soon_;
2006-08-04 23:10:59 +00:00
};
// An interface for Task_function. This is a convenience class to run
// a single function.
class Task_function_runner
{
public:
virtual ~Task_function_runner()
{ }
virtual void
run(Workqueue*, const Task*) = 0;
};
// A simple task which waits for a blocker and then runs a function.
class Task_function : public Task
{
public:
// RUNNER and BLOCKER should be allocated using new, and will be
// deleted after the task runs.
2007-11-22 00:05:51 +00:00
Task_function(Task_function_runner* runner, Task_token* blocker,
const char* name)
: runner_(runner), blocker_(blocker), name_(name)
{ gold_assert(blocker != NULL); }
~Task_function()
{
delete this->runner_;
delete this->blocker_;
}
// The standard task methods.
// Wait until the task is unblocked.
Task_token*
is_runnable()
{ return this->blocker_->is_blocked() ? this->blocker_ : NULL; }
// This type of task does not normally hold any locks.
virtual void
locks(Task_locker*)
{ }
// Run the action.
void
run(Workqueue* workqueue)
{ this->runner_->run(workqueue, this); }
2007-11-22 00:05:51 +00:00
// The debugging name.
std::string
get_name() const
{ return this->name_; }
private:
Task_function(const Task_function&);
Task_function& operator=(const Task_function&);
Task_function_runner* runner_;
Task_token* blocker_;
2007-11-22 00:05:51 +00:00
const char* name_;
};
// The workqueue itself.
2006-08-04 23:10:59 +00:00
class Workqueue_threader;
2006-08-04 23:10:59 +00:00
class Workqueue
{
public:
Workqueue(const General_options&);
~Workqueue();
// Add a new task to the work queue.
void
queue(Task*);
// Add a new task to the work queue which should run soon. If the
// task is ready, it will be run before any tasks added using
// queue().
void
queue_soon(Task*);
// Add a new task to the work queue which should run next if it is
// ready.
void
queue_next(Task*);
// Process all the tasks on the work queue. This function runs
// until all tasks have completed. The argument is the thread
// number, used only for debugging.
2006-08-04 23:10:59 +00:00
void
process(int);
2006-08-04 23:10:59 +00:00
// Set the desired thread count--the number of threads we want to
// have running.
void
set_thread_count(int);
* readsyms.cc (Read_symbols::incompatible_warning): New function. (Read_symbols::requeue): New function. (Read_symbols::do_read_symbols): If make_elf_object fails because the target type is not configured, and the file was searched for, issue a warning and retry with the next directory. (Add_symbols::run): If the file has an incompatible format, and it was searched for, requeue the Read_symbols task. On error, release the object. * readsyms.h (class Read_symbols): Add dirindex_ field. Add dirindex parameter to constructor. Change all callers. Declare incompatible_warning and requeue. (class Add_symbols): Add dirpath_, dirindex_, mapfile_, input_argument_ and input_group_ fields. Add them to constructor. Change all callers. (class Read_script): Add dirindex_ field. Add it to constructor. Change all callers. * archive.cc (Archive::setup): Remove input_objects parameter. Change all callers. (Archive::get_file_and_offset): Likewise. (Archive::read_all_symbols): Likewise. (Archive::read_symbols): Likewise. (Archive::get_elf_object_for_member): Remove input_objects parameter. Add punconfigured parameter. Change all callers. (Archive::add_symbols): Change return type to bool. Check return value of include_member. (Archive::include_all_members): Likewise. (Archive::include_member): Change return type to bool. Return false if first included object has incompatible target. Set included_member_ field. (Add_archive_symbols::run): If add_symbols returns false, requeue Read_symbols task. * archive.h (class Archive): Add included_member_ field. Initialize it in constructor. Add input_file and searched_for methods. Update declarations. (class Add_archive_symbols): Add dirpath_, dirindex_, and input_argument_ fields. Add them to constructor. Change all callers. * script.cc: Include "target-select.h". (class Parser_closure): Add skip_on_incompatible_target_ and found_incompatible_target_ fields. Add skip_on_incompatible_target parameter to constructor. Change all callers. Add methods skip_on_incompatible_target, clear_skip_on_incompatible_target, found_incompatible_target, and set_found_incompatible_target. (read_input_script): Add dirindex parameter. Change all callers. If parser finds an incompatible target, requeue Read_symbols task. (script_set_symbol): Clear skip_on_incompatible_target in closure. (script_add_assertion, script_parse_option): Likewise. (script_start_sections, script_add_phdr): Likewise. (script_check_output_format): New function. * script.h (read_input_script): Update declaration. * script-c.h (script_check_output_format): Declare. * yyscript.y (file_cmd): Handle OUTPUT_FORMAT. (ignore_cmd): Remove OUTPUT_FORMAT. * fileread.cc (Input_file::Input_file): Add explicit this. (Input_file::will_search_for): New function. (Input_file::open): Add pindex parameter. Change all callers. * fileread.h (class Input_file): Add input_file_argument method. Declare will_search_for. Update declarations. * object.cc (make_elf_object): Add punconfigured parameter. Change all callers. * object.h (class Object): Make input_file public. Add searched_for method. (make_elf_object): Update declaration. * dirsearch.cc (Dirsearch::find): Add pindex parameter. Use it to restart search. * dirsearch.h (class Dirsearch): Update declaration. * options.h (class General_options): Add --warn-search-mismatch. * parameters.cc (Parameters::is_compatible_target): New function. * parameters.h (class Parameters): Declare is_compatible_target. * workqueue.cc (Workqueue::add_blocker): New function. * workqueue.h (class Workqueue): Declare add_blocker.
2009-03-14 05:56:46 +00:00
// Add a new blocker to an existing Task_token. This must be done
// with the workqueue lock held. This should not be done routinely,
// only in special circumstances.
void
add_blocker(Task_token*);
2006-08-04 23:10:59 +00:00
private:
// This class can not be copied.
Workqueue(const Workqueue&);
Workqueue& operator=(const Workqueue&);
// Add a task to a queue.
2007-11-22 00:05:51 +00:00
void
add_to_queue(Task_list* queue, Task* t, bool front);
2006-08-04 23:10:59 +00:00
// Find a runnable task, or wait for one.
Task*
find_runnable_or_wait(int thread_number);
2006-08-04 23:10:59 +00:00
// Find a runnable task.
2007-11-22 00:05:51 +00:00
Task*
find_runnable();
2006-08-04 23:10:59 +00:00
// Find a runnable task in a list.
Task*
find_runnable_in_list(Task_list*);
2006-08-04 23:10:59 +00:00
// Find an run a task.
2007-11-22 00:05:51 +00:00
bool
find_and_run_task(int);
2007-11-22 00:05:51 +00:00
// Release the locks for a Task. Return the next Task to run.
Task*
release_locks(Task*, Task_locker*);
2006-08-04 23:10:59 +00:00
// Store T into *PRET, or queue it as appropriate.
bool
return_or_queue(Task* t, bool is_blocker, Task** pret);
// Return whether to cancel this thread.
bool
should_cancel_thread(int thread_number);
2006-08-04 23:10:59 +00:00
// Master Workqueue lock. This controls access to the following
// member variables.
Lock lock_;
2007-11-22 00:05:51 +00:00
// List of tasks to execute soon.
Task_list first_tasks_;
// List of tasks to execute after the ones in first_tasks_.
2006-08-04 23:10:59 +00:00
Task_list tasks_;
// Number of tasks currently running.
int running_;
// Number of tasks waiting for a lock to release.
int waiting_;
// Condition variable associated with lock_. This is signalled when
// there may be a new Task to execute.
Condvar condvar_;
// The threading implementation. This is set at construction time
// and not changed thereafter.
Workqueue_threader* threader_;
2006-08-04 23:10:59 +00:00
};
} // End namespace gold.
#endif // !defined(GOLD_WORKQUEUE_H)