gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gold / workqueue.cc
index 647daf2ed6ee9a468a2530fe5906aacabd6ccfb7..157582eefbaee8968f04cbb1235deb74c24b4714 100644 (file)
@@ -1,6 +1,6 @@
 // workqueue.cc -- the workqueue for gold
 
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright (C) 2006-2020 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -24,6 +24,7 @@
 
 #include "debug.h"
 #include "options.h"
+#include "timer.h"
 #include "workqueue.h"
 #include "workqueue-internal.h"
 
@@ -50,6 +51,24 @@ Task_list::push_back(Task* t)
     }
 }
 
+// Add T to the front of the list.
+
+inline void
+Task_list::push_front(Task* t)
+{
+  gold_assert(t->list_next() == NULL);
+  if (this->head_ == NULL)
+    {
+      this->head_ = t;
+      this->tail_ = t;
+    }
+  else
+    {
+      t->set_list_next(this->head_);
+      this->head_ = t;
+    }
+}
+
 // Remove and return the first Task waiting for this lock to be
 // released.
 
@@ -91,7 +110,7 @@ class Workqueue_threader_single : public Workqueue_threader
   { gold_assert(thread_count > 0); }
 
   bool
-  should_cancel_thread()
+  should_cancel_thread(int)
   { return false; }
 };
 
@@ -130,19 +149,25 @@ Workqueue::~Workqueue()
 // waiting for a Token.
 
 void
-Workqueue::add_to_queue(Task_list* queue, Task* t)
+Workqueue::add_to_queue(Task_list* queue, Task* t, bool front)
 {
   Hold_lock hl(this->lock_);
 
   Task_token* token = t->is_runnable();
   if (token != NULL)
     {
-      token->add_waiting(t);
+      if (front)
+       token->add_waiting_front(t);
+      else
+       token->add_waiting(t);
       ++this->waiting_;
     }
   else
     {
-      queue->push_back(t);
+      if (front)
+       queue->push_front(t);
+      else
+       queue->push_back(t);
       // Tell any waiting thread that there is work to do.
       this->condvar_.signal();
     }
@@ -153,24 +178,33 @@ Workqueue::add_to_queue(Task_list* queue, Task* t)
 void
 Workqueue::queue(Task* t)
 {
-  this->add_to_queue(&this->tasks_, t);
+  this->add_to_queue(&this->tasks_, t, false);
+}
+
+// Queue a task which should run soon.
+
+void
+Workqueue::queue_soon(Task* t)
+{
+  t->set_should_run_soon();
+  this->add_to_queue(&this->first_tasks_, t, false);
 }
 
-// Add a task to the front of the queue.
+// Queue a task which should run next.
 
 void
-Workqueue::queue_front(Task* t)
+Workqueue::queue_next(Task* t)
 {
   t->set_should_run_soon();
-  this->add_to_queue(&this->first_tasks_, t);
+  this->add_to_queue(&this->first_tasks_, t, true);
 }
 
 // Return whether to cancel the current thread.
 
 inline bool
-Workqueue::should_cancel_thread()
+Workqueue::should_cancel_thread(int thread_number)
 {
-  return this->threader_->should_cancel_thread();
+  return this->threader_->should_cancel_thread(thread_number);
 }
 
 // Find a runnable task in TASKS.  Return NULL if none could be found.
@@ -230,7 +264,7 @@ Workqueue::find_runnable_or_wait(int thread_number)
          return NULL;
        }
 
-      if (this->should_cancel_thread())
+      if (this->should_cancel_thread(thread_number))
        return NULL;
 
       gold_debug(DEBUG_TASK, "%3d sleeping", thread_number);
@@ -278,10 +312,24 @@ Workqueue::find_and_run_task(int thread_number)
       gold_debug(DEBUG_TASK, "%3d running   task %s", thread_number,
                 t->name().c_str());
 
+      Timer timer;
+      if (is_debugging_enabled(DEBUG_TASK))
+        timer.start();
+
       t->run(this);
 
-      gold_debug(DEBUG_TASK, "%3d completed task %s", thread_number,
-                t->name().c_str());
+      if (is_debugging_enabled(DEBUG_TASK))
+        {
+          Timer::TimeStats elapsed = timer.get_elapsed_time();
+
+          gold_debug(DEBUG_TASK,
+                     "%3d completed task %s "
+                     "(user: %ld.%06ld sys: %ld.%06ld wall: %ld.%06ld)",
+                     thread_number,  t->name().c_str(),
+                     elapsed.user / 1000, (elapsed.user % 1000) * 1000,
+                     elapsed.sys / 1000, (elapsed.sys % 1000) * 1000,
+                     elapsed.wall / 1000, (elapsed.wall % 1000) * 1000);
+        }
 
       Task* next;
       {
@@ -461,4 +509,13 @@ Workqueue::set_thread_count(int threads)
   this->condvar_.broadcast();
 }
 
+// Add a new blocker to an existing Task_token.
+
+void
+Workqueue::add_blocker(Task_token* token)
+{
+  Hold_lock hl(this->lock_);
+  token->add_blocker();
+}
+
 } // End namespace gold.
This page took 0.026406 seconds and 4 git commands to generate.