This is the mail archive of the gdb-patches@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]

RFC: make thread_list static


I've had this patch on a branch for a while and thought I would send it
today.

I noticed that thread_list is only used in one place outside of
thread.c.  It seems generally preferable to me to keep things like this
private.  So, this patch makes it static and updates the one user.

Bootstrapped and regtested on x86-64 Fedora 16.

Let me know what you think.

Tom

2012-11-27  Tom Tromey  <tromey@redhat.com>

	* thread.c (thread_list): Now static.
	* remote.c (struct pending_resumption_data): New.
	(pending_thread_callback): New function.
	(append_pending_thread_resumptions): Use iterate_over_threads.
	* gdbthread.h (ALL_THREADS): Remove.
	(thread_list): Don't declare.

diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 0250555..7cd66b6 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -301,11 +301,6 @@ void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
 typedef int (*thread_callback_func) (struct thread_info *, void *);
 extern struct thread_info *iterate_over_threads (thread_callback_func, void *);
 
-/* Traverse all threads.  */
-
-#define ALL_THREADS(T)				\
-  for (T = thread_list; T; T = T->next)
-
 extern int thread_count (void);
 
 /* Switch from one thread to another.  */
@@ -396,6 +391,4 @@ extern struct thread_info* inferior_thread (void);
 
 extern void update_thread_list (void);
 
-extern struct thread_info *thread_list;
-
 #endif /* GDBTHREAD_H */
diff --git a/gdb/remote.c b/gdb/remote.c
index 929d4f5..a67634d 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4665,26 +4665,53 @@ append_resumption (char *p, char *endp,
   return p;
 }
 
+/* A structure to pass data from append_pending_thread_resumptions to
+   its worker.  */
+
+struct pending_resumption_data
+{
+  ptid_t ptid;
+  char *result;
+  char *endp;
+};
+
+/* A callback for iterate_over_threads that does the work for
+   append_pending_thread_resumptions.  */
+
+static int
+pending_thread_callback (struct thread_info *thread, void *arg)
+{
+  struct pending_resumption_data *data = arg;
+
+  if (ptid_match (thread->ptid, data->ptid)
+      && !ptid_equal (inferior_ptid, thread->ptid)
+      && thread->suspend.stop_signal != GDB_SIGNAL_0
+      && signal_pass_state (thread->suspend.stop_signal))
+    {
+      data->result = append_resumption (data->result, data->endp, thread->ptid,
+					0, thread->suspend.stop_signal);
+      thread->suspend.stop_signal = GDB_SIGNAL_0;
+    }
+
+  /* Keep going.  */
+  return 0;
+}
+
 /* Append a vCont continue-with-signal action for threads that have a
    non-zero stop signal.  */
 
 static char *
 append_pending_thread_resumptions (char *p, char *endp, ptid_t ptid)
 {
-  struct thread_info *thread;
+  struct pending_resumption_data data;
 
-  ALL_THREADS (thread)
-    if (ptid_match (thread->ptid, ptid)
-	&& !ptid_equal (inferior_ptid, thread->ptid)
-	&& thread->suspend.stop_signal != GDB_SIGNAL_0
-	&& signal_pass_state (thread->suspend.stop_signal))
-      {
-	p = append_resumption (p, endp, thread->ptid,
-			       0, thread->suspend.stop_signal);
-	thread->suspend.stop_signal = GDB_SIGNAL_0;
-      }
+  data.ptid = ptid;
+  data.result = p;
+  data.endp = endp;
 
-  return p;
+  iterate_over_threads (pending_thread_callback, &data);
+
+  return data.result;
 }
 
 /* Resume the remote inferior by using a "vCont" packet.  The thread
diff --git a/gdb/thread.c b/gdb/thread.c
index 7e8eec5..ba4cbc8 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -54,7 +54,7 @@ void _initialize_thread (void);
 
 /* Prototypes for local functions.  */
 
-struct thread_info *thread_list = NULL;
+static struct thread_info *thread_list = NULL;
 static int highest_thread_num;
 
 static void thread_command (char *tidstr, int from_tty);


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