This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Remove usage of find_inferior in last_thread_of_process_p


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e4eb0dec0b9219a27ea6b9769f098fff34612779

commit e4eb0dec0b9219a27ea6b9769f098fff34612779
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Sat Dec 2 20:36:36 2017 -0500

    Remove usage of find_inferior in last_thread_of_process_p
    
    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.

Diff:
---
 gdb/gdbserver/ChangeLog   |  6 ++++++
 gdb/gdbserver/linux-low.c | 38 ++++++++++++++++----------------------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 62ff8e6..f4f77aa 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,11 @@
 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.
 	* inferiors.h (find_inferior_in_random): Remove.
 	* linux-low.c (status_pending_p_callback): Return bool, accept
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index ac51d11..2e63468 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -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.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]