public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 01/21] gdb: use intrusive_list for struct ui linked list
Date: Fri,  8 Sep 2023 14:22:55 -0400	[thread overview]
Message-ID: <20230908190227.96319-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230908190227.96319-1-simon.marchi@efficios.com>

Replace the hand-made list with intrusive_list.

Change-Id: If003cafda2f680794b9b6ae63236f19dd40908af
---
 gdb/infrun.c |  4 ++--
 gdb/top.c    |  4 ++--
 gdb/ui.c     | 29 ++++-------------------------
 gdb/ui.h     | 29 ++++++++++++-----------------
 4 files changed, 20 insertions(+), 46 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4730d2904423..aaa7b2de14cd 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -5454,9 +5454,9 @@ handle_no_resumed (struct execution_control_state *ecs)
     {
       bool any_sync = false;
 
-      for (ui *ui : all_uis ())
+      for (ui &ui : all_uis ())
 	{
-	  if (ui->prompt_state == PROMPT_BLOCKED)
+	  if (ui.prompt_state == PROMPT_BLOCKED)
 	    {
 	      any_sync = true;
 	      break;
diff --git a/gdb/top.c b/gdb/top.c
index 2322e55f1db4..483e201140e7 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1783,9 +1783,9 @@ quit_force (int *exit_arg, int from_tty)
 
 	  /* History is currently shared between all UIs.  If there's
 	     any UI with a terminal, save history.  */
-	  for (ui *ui : all_uis ())
+	  for (ui &ui : all_uis ())
 	    {
-	      if (ui->input_interactive_p ())
+	      if (ui.input_interactive_p ())
 		{
 		  save = 1;
 		  break;
diff --git a/gdb/ui.c b/gdb/ui.c
index 38ec61ea6731..f3dd14bfd3e0 100644
--- a/gdb/ui.c
+++ b/gdb/ui.c
@@ -33,7 +33,7 @@
 
 struct ui *main_ui;
 struct ui *current_ui;
-struct ui *ui_list;
+intrusive_list<ui> ui_list;
 
 /* The highest UI number ever assigned.  */
 
@@ -56,34 +56,13 @@ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
 {
   unbuffer_stream (instream_);
 
-  if (ui_list == NULL)
-    ui_list = this;
-  else
-    {
-      struct ui *last;
-
-      for (last = ui_list; last->next != NULL; last = last->next)
-	;
-      last->next = this;
-    }
+  ui_list.push_back (*this);
 }
 
 ui::~ui ()
 {
-  struct ui *ui, *uiprev;
-
-  uiprev = NULL;
-
-  for (ui = ui_list; ui != NULL; uiprev = ui, ui = ui->next)
-    if (ui == this)
-      break;
-
-  gdb_assert (ui != NULL);
-
-  if (uiprev != NULL)
-    uiprev->next = next;
-  else
-    ui_list = next;
+  gdb_assert (this->is_linked ());
+  ui_list.erase (ui_list.iterator_to (*this));
 
   delete m_gdb_stdin;
   delete m_gdb_stdout;
diff --git a/gdb/ui.h b/gdb/ui.h
index ed75e041e5f2..c5e65c0393d8 100644
--- a/gdb/ui.h
+++ b/gdb/ui.h
@@ -51,7 +51,7 @@ enum prompt_state
    example, to create a separate MI channel on its own stdio
    streams.  */
 
-struct ui
+struct ui : public intrusive_list_node<ui>
 {
   /* Create a new UI.  */
   ui (FILE *instream, FILE *outstream, FILE *errstream);
@@ -59,9 +59,6 @@ struct ui
 
   DISABLE_COPY_AND_ASSIGN (ui);
 
-  /* Pointer to next in singly-linked list.  */
-  struct ui *next = nullptr;
-
   /* Convenient handle (UI number).  Unique across all UIs.  */
   int num;
 
@@ -172,16 +169,17 @@ extern struct ui *main_ui;
 extern struct ui *current_ui;
 
 /* The list of all UIs.  */
-extern struct ui *ui_list;
+extern intrusive_list<ui> ui_list;
 
 /* State for SWITCH_THRU_ALL_UIS.  */
 class switch_thru_all_uis
 {
 public:
 
-  switch_thru_all_uis () : m_iter (ui_list), m_save_ui (&current_ui)
+  switch_thru_all_uis () : m_iter (ui_list.begin ()), m_save_ui (&current_ui)
   {
-    current_ui = ui_list;
+    if (m_iter != ui_list.end ())
+      current_ui = &*m_iter;
   }
 
   DISABLE_COPY_AND_ASSIGN (switch_thru_all_uis);
@@ -189,22 +187,21 @@ class switch_thru_all_uis
   /* If done iterating, return true; otherwise return false.  */
   bool done () const
   {
-    return m_iter == NULL;
+    return m_iter == ui_list.end ();
   }
 
   /* Move to the next UI, setting current_ui if iteration is not yet
      complete.  */
   void next ()
   {
-    m_iter = m_iter->next;
-    if (m_iter != NULL)
-      current_ui = m_iter;
+    ++m_iter;
+    if (m_iter != ui_list.end ())
+      current_ui = &*m_iter;
   }
 
  private:
-
   /* Used to iterate through the UIs.  */
-  struct ui *m_iter;
+  intrusive_list<ui>::iterator m_iter;
 
   /* Save and restore current_ui.  */
   scoped_restore_tmpl<struct ui *> m_save_ui;
@@ -215,13 +212,11 @@ class switch_thru_all_uis
 #define SWITCH_THRU_ALL_UIS()		\
   for (switch_thru_all_uis stau_state; !stau_state.done (); stau_state.next ())
 
-using ui_range = next_range<ui>;
-
 /* An adapter that can be used to traverse over all UIs.  */
 static inline
-ui_range all_uis ()
+intrusive_list<ui> &all_uis ()
 {
-  return ui_range (ui_list);
+  return ui_list;
 }
 
 #endif /* UI_H */
-- 
2.42.0


  reply	other threads:[~2023-09-08 19:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 18:22 [PATCH 00/21] ui / interp cleansup Simon Marchi
2023-09-08 18:22 ` Simon Marchi [this message]
2023-09-08 18:22 ` [PATCH 02/21] gdb: make interp_lookup_existing a method of struct ui Simon Marchi
2023-09-08 18:22 ` [PATCH 03/21] gdb: make interp_add " Simon Marchi
2023-09-08 18:22 ` [PATCH 04/21] gdb: make interp_lookup " Simon Marchi
2023-09-12  9:15   ` Andrew Burgess
2023-09-12 14:38     ` Simon Marchi
2023-09-08 18:22 ` [PATCH 05/21] gdb: remove ui:::add_interp and ui::lookup_existing_interp Simon Marchi
2023-09-08 18:23 ` [PATCH 06/21] gdb: uncover some current_ui uses in interp_set Simon Marchi
2023-09-08 18:23 ` [PATCH 07/21] gdb: add backlink to ui in interp Simon Marchi
2023-09-08 18:23 ` [PATCH 08/21] gdb: pass ui down to gdb_setup_readline and gdb_disable_readline Simon Marchi
2023-09-08 18:23 ` [PATCH 09/21] gdb/python: use m_ui instead of current_ui in dap_interp::init Simon Marchi
2023-09-08 18:23 ` [PATCH 10/21] gdb/mi: use m_ui instead of current_ui in mi_interp::init Simon Marchi
2023-09-08 18:23 ` [PATCH 11/21] gdb/cli: use m_ui instead of current_ui in cli_interp::resume Simon Marchi
2023-09-12 10:40   ` Andrew Burgess
2023-09-12 15:42     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 12/21] gdb/tui: use m_ui instead of current_ui in tui_interp::resume Simon Marchi
2023-09-12 10:41   ` Andrew Burgess
2023-09-08 18:23 ` [PATCH 13/21] gdb/mi: use m_ui instead of current_ui in mi_interp::resume Simon Marchi
2023-09-12 10:44   ` Andrew Burgess
2023-09-12 16:36     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 14/21] gdb/cli: use m_ui instead of current_ui in cli_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 15/21] gdb/tui: use m_ui instead of current_ui in tui_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 16/21] gdb/mi: use m_ui instead of current_ui in mi_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 17/21] gdb: pass current_ui down to interp_set Simon Marchi
2023-09-12 10:54   ` Andrew Burgess
2023-09-12 17:17     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 18/21] gdb: make interp_set a method of struct ui Simon Marchi
2023-09-12 10:58   ` Andrew Burgess
2023-09-12 17:23     ` Simon Marchi
2023-09-12 13:41   ` Tom Tromey
2023-09-12 17:32     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 19/21] gdb: pass down current_ui to set_top_level_interpreter Simon Marchi
2023-09-11 15:15   ` Simon Marchi
2023-09-08 18:23 ` [PATCH 20/21] gdb: make set_top_level_interpreter a method of struct ui Simon Marchi
2023-09-12 11:20   ` Andrew Burgess
2023-09-12 17:41     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 21/21] gdb: make top_level_interpreter " Simon Marchi
2023-09-12 11:35   ` Andrew Burgess
2023-09-12 17:54     ` Simon Marchi
2023-09-12 11:38 ` [PATCH 00/21] ui / interp cleansup Andrew Burgess
2023-09-12 17:51   ` Simon Marchi
2023-09-12 18:06   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230908190227.96319-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).