From patchwork Thu Jan 10 18:06:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31023 Received: (qmail 81046 invoked by alias); 10 Jan 2019 18:06:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 81033 invoked by uid 89); 10 Jan 2019 18:06:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2013, safely, sk:forward X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.48.38) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Jan 2019 18:06:26 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway20.websitewelcome.com (Postfix) with ESMTP id D894E400CD1ED for ; Thu, 10 Jan 2019 12:06:24 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id heimgY1NX2PzOheimgC8OM; Thu, 10 Jan 2019 12:06:24 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=X67SImBTAYcpDjMz3pG/LLZEDolBknoXGbZSGgqNM8Y=; b=MJs/HqylpbviJ3TsNwCQPDRfzZ +Iiys9iinMrw0RaQ6Avyqujh9xY7b6OGET12gGA5aA30fP5maVGjUR1doUcFZhofFwv3R3AZpCKDP fHGlmm7MFlynDrWjqcD84FovA; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:46736 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gheim-000XAV-JZ; Thu, 10 Jan 2019 12:06:24 -0600 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH 00/12] Remove some ALL_* iteration macros References: <20181125165439.13773-1-tom@tromey.com> Date: Thu, 10 Jan 2019 11:06:23 -0700 In-Reply-To: (Pedro Alves's message of "Thu, 10 Jan 2019 16:44:26 +0000") Message-ID: <87muo8peu8.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.90 (gnu/linux) MIME-Version: 1.0 >>>>> "Pedro" == Pedro Alves writes: >> There are still a few more such macros that could be converted. And, >> I think inf_threads_iterator could be converted to use next_iterator. >> I can do some of this if there's interest. Pedro> If it's a natural fit, then I think it'd be nice. Is there a downside? I don't think there is one. What do you think of this? Tom commit f4cd9886913b5216ed6073af23d250401f006551 Author: Tom Tromey Date: Thu Jan 10 10:50:43 2019 -0700 Replace inf_threads_iterator with next_iterator This changes inf_threads_iterator and some range adapters in thread-iter.h to use next_iterator and next_adapter instead. gdb/ChangeLog 2019-01-10 Tom Tromey * thread-iter.h (inf_threads_iterator): Use next_iterator. (basic_inf_threads_range): Remove. (inf_threads_range, inf_non_exited_threads_range) (safe_inf_threads_range): Use next_adapter. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 32fe0bbe814..ac1dd540ef7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-01-10 Tom Tromey + + * thread-iter.h (inf_threads_iterator): Use next_iterator. + (basic_inf_threads_range): Remove. + (inf_threads_range, inf_non_exited_threads_range) + (safe_inf_threads_range): Use next_adapter. + 2019-01-10 Tom Tromey * objfiles.h (objfile::reset_psymtabs): Update. diff --git a/gdb/thread-iter.h b/gdb/thread-iter.h index a1145d4938a..be6ab73c686 100644 --- a/gdb/thread-iter.h +++ b/gdb/thread-iter.h @@ -20,68 +20,13 @@ #define THREAD_ITER_H #include "common/filtered-iterator.h" +#include "common/next-iterator.h" #include "common/safe-iterator.h" /* A forward iterator that iterates over a given inferior's threads. */ -class inf_threads_iterator -{ -public: - typedef inf_threads_iterator self_type; - typedef struct thread_info *value_type; - typedef struct thread_info *&reference; - typedef struct thread_info **pointer; - typedef std::forward_iterator_tag iterator_category; - typedef int difference_type; - - /* Create an iterator pointing at HEAD. This takes a thread pointer - instead of an inferior pointer to avoid circular dependencies - between the thread and inferior header files. */ - explicit inf_threads_iterator (struct thread_info *head) - : m_thr (head) - {} - - /* Create a one-past-end iterator. */ - inf_threads_iterator () - : m_thr (nullptr) - {} - - inf_threads_iterator& operator++ () - { - m_thr = m_thr->next; - return *this; - } - - thread_info *operator* () const { return m_thr; } - - bool operator!= (const inf_threads_iterator &other) const - { return m_thr != other.m_thr; } - -private: - /* The currently-iterated thread. NULL if we reached the end of the - list. */ - thread_info *m_thr; -}; - -/* A range adapter that makes it possible to iterate over an - inferior's thread list with range-for. */ -template -struct basic_inf_threads_range -{ - friend struct inferior; -private: - explicit basic_inf_threads_range (struct thread_info *head) - : m_head (head) - {} - -public: - Iterator begin () const { return Iterator (m_head); } - Iterator end () const { return Iterator (); } - -private: - thread_info *m_head; -}; +using inf_threads_iterator = next_iterator; /* A forward iterator that iterates over all threads of all inferiors. */ @@ -223,19 +168,19 @@ using safe_inf_threads_iterator of an inferior with range-for. */ using inf_threads_range - = basic_inf_threads_range; + = next_adapter; /* A range adapter that makes it possible to iterate over all non-exited threads of an inferior with range-for. */ using inf_non_exited_threads_range - = basic_inf_threads_range; + = next_adapter; /* A range adapter that makes it possible to iterate over all threads of an inferior with range-for, safely. */ using safe_inf_threads_range - = basic_inf_threads_range; + = next_adapter; /* A range adapter that makes it possible to iterate over all threads of all inferiors with range-for. */