From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6F5DF3858C5E for ; Fri, 8 Sep 2023 19:02:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F5DF3858C5E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0607A1E0C2; Fri, 8 Sep 2023 15:02:29 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 01/21] gdb: use intrusive_list for struct ui linked list Date: Fri, 8 Sep 2023 14:22:55 -0400 Message-ID: <20230908190227.96319-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230908190227.96319-1-simon.marchi@efficios.com> References: <20230908190227.96319-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3497.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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_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 { /* 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_list; /* State for SWITCH_THRU_ALL_UIS. */ class switch_thru_all_uis { public: - switch_thru_all_uis () : m_iter (ui_list), m_save_ui (¤t_ui) + switch_thru_all_uis () : m_iter (ui_list.begin ()), m_save_ui (¤t_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::iterator m_iter; /* Save and restore current_ui. */ scoped_restore_tmpl 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; - /* An adapter that can be used to traverse over all UIs. */ static inline -ui_range all_uis () +intrusive_list &all_uis () { - return ui_range (ui_list); + return ui_list; } #endif /* UI_H */ -- 2.42.0