From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29631 invoked by alias); 27 Nov 2012 18:30:58 -0000 Received: (qmail 29622 invoked by uid 22791); 27 Nov 2012 18:30:56 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Nov 2012 18:30:49 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qARIUfOt030258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 27 Nov 2012 13:30:49 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qARIUJ5H030228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 27 Nov 2012 13:30:33 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Subject: RFC: make thread_list static Date: Tue, 27 Nov 2012 18:30:00 -0000 Message-ID: <87y5hmdhl0.fsf@fleche.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-11/txt/msg00764.txt.bz2 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 * 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);