diff options
author | Yao Qi <yao@codesourcery.com> | 2013-10-04 07:42:06 +0000 |
---|---|---|
committer | Yao Qi <yao@codesourcery.com> | 2013-10-04 07:42:06 +0000 |
commit | f48ff2a7d3f69653dbf164e03d3397de8f6ba7c0 (patch) | |
tree | c865c15272902c555bae310d136f73eee5db53c7 /gdb/remote-notif.c | |
parent | 5965e02896b242f2ffe086def9c83a205eef31aa (diff) | |
download | gdb-f48ff2a7d3f69653dbf164e03d3397de8f6ba7c0.zip gdb-f48ff2a7d3f69653dbf164e03d3397de8f6ba7c0.tar.gz gdb-f48ff2a7d3f69653dbf164e03d3397de8f6ba7c0.tar.bz2 |
Move pending_event to remote_notif_state.
This patch moves pending_event to remote_notif_state. All pending
events are destroyed in remote_notif_state_xfree. However,
discard_pending_stop_replies release pending event too, so the pending
event of stop notification is released twice, we need some refactor
here. We add a new function discard_pending_stop_replies_in_queue
which only discard events in stop_reply_queue, and let
remote_notif_state_xfree release pending event for all notif_client.
After this change, discard_pending_stop_replies is only attached to
ifnerior_exit observer, so the INF can't be NULL any more. The
NULL checking is removed too.
gdb:
2013-10-04 Yao Qi <yao@codesourcery.com>
* remote-notif.h (REMOTE_NOTIF_ID): New enum.
(struct notif_client) <pending_event>: Moved
to struct remote_notif_state.
<id>: New field.
(struct remote_notif_state) <pending_event>: New field.
(notif_event_xfree): Declare.
* remote-notif.c (handle_notification): Adjust.
(notif_event_xfree): New function.
(do_notif_event_xfree): Call notif_event_xfree.
(remote_notif_state_xfree): Call notif_event_xfree to free
each element in field pending_event.
* remote.c (discard_pending_stop_replies): Remove declaration.
(discard_pending_stop_replies_in_queue): Declare.
(remote_close): Call discard_pending_stop_replies_in_queue
instead of discard_pending_stop_replies.
(remote_start_remote): Adjust.
(stop_reply_xfree): Call notif_event_xfree.
(notif_client_stop): Adjust initialization.
(remote_notif_remove_all): Rename it to ...
(remove_stop_reply_for_inferior): ... this. Update comments.
Don't check INF is NULL.
(discard_pending_stop_replies): Return early if notif_state is
NULL. Adjust. Don't check INF is NULL.
(remote_notif_get_pending_events): Adjust.
(discard_pending_stop_replies_in_queue): New function.
(remote_wait_ns): Likewise.
Diffstat (limited to 'gdb/remote-notif.c')
-rw-r--r-- | gdb/remote-notif.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c index 905b8a1..0d59279 100644 --- a/gdb/remote-notif.c +++ b/gdb/remote-notif.c @@ -51,6 +51,8 @@ static struct notif_client *notifs[] = ¬if_client_stop, }; +gdb_static_assert (ARRAY_SIZE (notifs) == REMOTE_NOTIF_LAST); + static void do_notif_event_xfree (void *arg); /* Parse the BUF for the expected notification NC, and send packet to @@ -141,7 +143,7 @@ handle_notification (struct remote_notif_state *state, char *buf) if (nc == NULL) return; - if (nc->pending_event) + if (state->pending_event[nc->id] != NULL) { /* We've already parsed the in-flight reply, but the stub for some reason thought we didn't, possibly due to timeout on its side. @@ -157,7 +159,7 @@ handle_notification (struct remote_notif_state *state, char *buf) /* Be careful to only set it after parsing, since an error may be thrown then. */ - nc->pending_event = event; + state->pending_event[nc->id] = event; /* Notify the event loop there's a stop reply to acknowledge and that there may be more events to fetch. */ @@ -210,19 +212,25 @@ handle_notification (struct remote_notif_state *state, char *buf) } } -/* Cleanup wrapper. */ +/* Invoke destructor of EVENT and xfree it. */ -static void -do_notif_event_xfree (void *arg) +void +notif_event_xfree (struct notif_event *event) { - struct notif_event *event = arg; - - if (event && event->dtr) + if (event != NULL && event->dtr != NULL) event->dtr (event); xfree (event); } +/* Cleanup wrapper. */ + +static void +do_notif_event_xfree (void *arg) +{ + notif_event_xfree (arg); +} + /* Return an allocated remote_notif_state. */ struct remote_notif_state * @@ -246,12 +254,17 @@ remote_notif_state_allocate (void) void remote_notif_state_xfree (struct remote_notif_state *state) { + int i; + QUEUE_free (notif_client_p, state->notif_queue); /* Unregister async_event_handler for notification. */ if (state->get_pending_events_token != NULL) delete_async_event_handler (&state->get_pending_events_token); + for (i = 0; i < REMOTE_NOTIF_LAST; i++) + notif_event_xfree (state->pending_event[i]); + xfree (state); } |