linux-fork.c: rewrite inf_has_multiple_threads
authorPedro Alves <palves@redhat.com>
Wed, 6 Mar 2019 18:29:19 +0000 (18:29 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 6 Mar 2019 18:29:19 +0000 (18:29 +0000)
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().

gdb/ChangeLog
gdb/linux-fork.c

index 7a7ee5fc807956b10965d94d9652ada5bd3a6848..f423232d95fa94579ce35ccb918968284942f19b 100644 (file)
@@ -1,3 +1,9 @@
+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>.
index 1c7b7ca123062ebf86fdb729e0dedf13109b095e..4bc454ba6dd9d570bf8f3667c70cd2ca3eae3fa1 100644 (file)
@@ -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
This page took 0.027297 seconds and 4 git commands to generate.