Remove usage of find_inferior in last_thread_of_process_p
authorSimon Marchi <simon.marchi@polymtl.ca>
Sun, 3 Dec 2017 01:36:36 +0000 (20:36 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sun, 3 Dec 2017 01:36:36 +0000 (20:36 -0500)
Replace it with find_thread.  I also modified the code a bit to use a
lambda and a boolean.

gdb/gdbserver/ChangeLog:

* linux-low.c (struct counter): Remove.
(second_thread_of_pid_p): Remove.
(last_thread_of_process_p): Use find_thread.

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c

index 62ff8e69701a5ce137c8bc4dedd6e1e7dfaf84ee..f4f77aa06de9cb429f26991603d859617dd1c106 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * linux-low.c (struct counter): Remove.
+       (second_thread_of_pid_p): Remove.
+       (last_thread_of_process_p): Use find_thread.
+
 2017-12-02  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * inferiors.c (find_inferior_in_random): Remove.
index ac51d1184c8710c904e86d4d81a9cccf5dc18d2d..2e634680051abfb20ac98d9cda559d7e6eb8af7b 100644 (file)
@@ -1241,33 +1241,27 @@ linux_attach (unsigned long pid)
   return 0;
 }
 
-struct counter
-{
-  int pid;
-  int count;
-};
-
 static int
-second_thread_of_pid_p (thread_info *thread, void *args)
+last_thread_of_process_p (int pid)
 {
-  struct counter *counter = (struct counter *) args;
+  bool seen_one = false;
 
-  if (thread->id.pid () == counter->pid)
+  thread_info *thread = find_thread (pid, [&] (thread_info *thread)
     {
-      if (++counter->count > 1)
-       return 1;
-    }
-
-  return 0;
-}
-
-static int
-last_thread_of_process_p (int pid)
-{
-  struct counter counter = { pid , 0 };
+      if (!seen_one)
+       {
+         /* This is the first thread of this process we see.  */
+         seen_one = true;
+         return false;
+       }
+      else
+       {
+         /* This is the second thread of this process we see.  */
+         return true;
+       }
+    });
 
-  return (find_inferior (&all_threads,
-                        second_thread_of_pid_p, &counter) == NULL);
+  return thread == NULL;
 }
 
 /* Kill LWP.  */
This page took 0.036519 seconds and 4 git commands to generate.