Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: RFC: make thread_list static
Date: Tue, 27 Nov 2012 18:30:00 -0000	[thread overview]
Message-ID: <87y5hmdhl0.fsf@fleche.redhat.com> (raw)

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);


             reply	other threads:[~2012-11-27 18:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-27 18:30 Tom Tromey [this message]
2012-11-28  7:27 ` Joel Brobecker
2012-11-28  8:41 ` Yao Qi
2012-11-28  9:27 ` Pedro Alves
2012-11-28 14:35   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y5hmdhl0.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox