aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2019-03-06 18:29:19 +0000
committerPedro Alves <palves@redhat.com>2019-03-06 18:29:19 +0000
commite52c971f17ac747a065388b54a909f44b5582cd9 (patch)
tree6d797a4bcec7cd518fdd9313b644c385a4be5d8e
parent06974e6c05556edb7122f45239c95045e882dc76 (diff)
downloadgdb-e52c971f17ac747a065388b54a909f44b5582cd9.zip
gdb-e52c971f17ac747a065388b54a909f44b5582cd9.tar.gz
gdb-e52c971f17ac747a065388b54a909f44b5582cd9.tar.bz2
linux-fork.c: rewrite inf_has_multiple_threads
There's no need to iterate over all threads of all inferiors here. gdb/ChangeLog: 2019-03-06 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().
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/linux-fork.c29
2 files changed, 15 insertions, 20 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7a7ee5f..f423232 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2019-03-06 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().
+
+2019-03-06 Pedro Alves <palves@redhat.com>
+
* linux-fork.c: Include <list>.
(fork_list): Now a std::list instance.
(fork_info): Add ctor, dtor, and in-class initialize all fields.
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 1c7b7ca..4bc454b 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