Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] linux-fork.c: rewrite inf_has_multiple_threads
Date: Tue, 05 Mar 2019 18:43:00 -0000	[thread overview]
Message-ID: <20190305184340.26768-4-palves@redhat.com> (raw)
In-Reply-To: <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  <palves@redhat.com>

	* 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
-- 
2.14.4


  parent reply	other threads:[~2019-03-05 18:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05 18:43 [PATCH 0/4] Make "checkpoint" not rely on inferior_ptid Pedro Alves
2019-03-05 18:43 ` [PATCH 2/4] C++ify fork_info, use std::list Pedro Alves
2019-03-05 18:43 ` Pedro Alves [this message]
2019-03-05 18:43 ` [PATCH 4/4] Eliminate fork_info::clobber_regs Pedro Alves
2019-03-05 18:43 ` [PATCH 1/4] Make "checkpoint" not rely on inferior_ptid Pedro Alves
2019-03-05 19:32   ` Tom Tromey
2019-03-05 19:46     ` Pedro Alves
2019-03-05 19:46 ` [PATCH 0/4] " 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=20190305184340.26768-4-palves@redhat.com \
    --to=palves@redhat.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