Re: [PATCH v4 2/9] add "this" pointers to more target APIs

Pedro Alves
2013-12-06T19:06:14Z

On 12/06/2013 06:23 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Tom> I'll remove "is_async". Unless you'd rather I remove "can_async".
>
> Pedro> No, that's fine. "is_async" would be my choice as well.
>
> I looked deeper than the two are still subtly different.
> Specifically, remote.c delegates to serial:
>
> return serial_can_async_p (rs->remote_desc);
> return serial_is_async_p (rs->remote_desc);
>
> And these really do differ:
>
> int
> serial_can_async_p (struct serial *scb)
> {
> return (scb->ops->async != NULL);
> }
>
> int
> serial_is_async_p (struct serial *scb)
> {
> return (scb->ops->async != NULL) && (scb->async_handler != NULL);
> }
>
>
> I find it a bit odd that the upper layers rely on the serial layer to do
> this bookkeeping.

Hmm, indeed. So target_is_async only returns true while
target_async (inferior_event_handler) is active.
Guess we need to go through target_is_async_p calls
and see how to eliminate them. The remote.c ones
seem simply replaceable with checking whether
we're doing a blocking wait, but the others look
more tricky.

(below's untested)

---
gdb/remote.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 2ac8c36..a164455 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -6001,7 +6001,7 @@ remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
int ret;
int is_notif;

- if (!target_is_async_p ())
+ if ((options & TARGET_WNOHANG) == 0)
{
ofunc = signal (SIGINT, sync_remote_interrupt);
/* If the user hit C-c before this packet, or between packets,
@@ -6020,7 +6020,7 @@ remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
wait_forever_enabled_p, &is_notif);

- if (!target_is_async_p ())
+ if ((options & TARGET_WNOHANG) == 0)
signal (SIGINT, ofunc);

/* GDB gets a notification. Return to core as this event is
--
1.7.11.7