From patchwork Tue Mar 5 18:43:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 31722 Received: (qmail 6207 invoked by alias); 5 Mar 2019 18:43:53 -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 6134 invoked by uid 89); 5 Mar 2019 18:43:53 -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, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:2019030 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Mar 2019 18:43:51 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B945AC01D33A for ; Tue, 5 Mar 2019 18:43:50 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 465465D782 for ; Tue, 5 Mar 2019 18:43:50 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 3/4] linux-fork.c: rewrite inf_has_multiple_threads Date: Tue, 5 Mar 2019 18:43:39 +0000 Message-Id: <20190305184340.26768-4-palves@redhat.com> In-Reply-To: <20190305184340.26768-1-palves@redhat.com> References: <20190305184340.26768-1-palves@redhat.com> There's no need to iterate over all threads of all inferiors here. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * linux-fork.c (inf_has_multiple_thread_cb): Delete. (inf_has_multiple_threads): Return 'bool' and rewrite using inferior_info::threads(). --- gdb/linux-fork.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 1c7b7ca123..4bc454ba6d 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -627,31 +627,20 @@ linux_fork_checkpointing_p (int pid) return (checkpointing_pid == pid); } -/* Callback for iterate over threads. Used to check whether - the current inferior is multi-threaded. Returns true as soon - as it sees the second thread of the current inferior. */ - -static int -inf_has_multiple_thread_cb (struct thread_info *tp, void *data) -{ - int *count_p = (int *) data; - - if (current_inferior ()->pid == tp->ptid.pid ()) - (*count_p)++; - - /* Stop the iteration if multiple threads have been detected. */ - return *count_p > 1; -} - /* Return true if the current inferior is multi-threaded. */ -static int -inf_has_multiple_threads (void) +static bool +inf_has_multiple_threads () { int count = 0; - iterate_over_threads (inf_has_multiple_thread_cb, &count); - return (count > 1); + /* Return true as soon as we see the second thread of the current + inferior. */ + for (thread_info *tp ATTRIBUTE_UNUSED : current_inferior ()->threads ()) + if (++count > 1) + return true; + + return false; } static void