From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] [GDBserver] Block and unblock SIGIO
Date: Tue, 26 Jan 2016 12:01:00 -0000 [thread overview]
Message-ID: <56A76003.1010308@redhat.com> (raw)
In-Reply-To: <1453802339-20401-3-git-send-email-yao.qi@linaro.org>
On 01/26/2016 09:58 AM, Yao Qi wrote:
> -static void
> -unblock_async_io (void)
> -{
> -#ifndef USE_WIN32API
> - sigset_t sigio_set;
> -
> - sigemptyset (&sigio_set);
> - sigaddset (&sigio_set, SIGIO);
> - sigprocmask (SIG_UNBLOCK, &sigio_set, NULL);
> -#endif
> -}
> +/* Asynchronous I/O support. SIGIO must be unblocked when waiting,
> + in order to accept Control-C from the client, and must be blocked
> + when talking to the client. */
>
> #ifdef __QNX__
> static void
> @@ -820,12 +813,19 @@ static int async_io_enabled;
> void
> enable_async_io (void)
> {
> +#ifndef USE_WIN32API
> + sigset_t sigio_set;
> +#endif
> +
> if (async_io_enabled)
> return;
>
> #ifndef USE_WIN32API
> - signal (SIGIO, input_interrupt);
> + sigemptyset (&sigio_set);
> + sigaddset (&sigio_set, SIGIO);
> + sigprocmask (SIG_UNBLOCK, &sigio_set, NULL);
> #endif
> +
> async_io_enabled = 1;
> #ifdef __QNX__
> nto_comctrl (1);
> @@ -836,12 +836,19 @@ enable_async_io (void)
> void
> disable_async_io (void)
> {
> +#ifndef USE_WIN32API
> + sigset_t sigio_set;
> +#endif
> +
> if (!async_io_enabled)
> return;
>
> #ifndef USE_WIN32API
> - signal (SIGIO, SIG_IGN);
> + sigemptyset (&sigio_set);
> + sigaddset (&sigio_set, SIGIO);
> + sigprocmask (SIG_BLOCK, &sigio_set, NULL);
> #endif
> +
I'd suggest factoring out this duplicate sigprocmask handling,
like, say, rename unblock_async_io and add a parameter:
/* Block or unblock SIGIO. */
static void
block_unblock_async_io (int block)
{
#ifndef USE_WIN32API
sigset_t sigio_set;
sigemptyset (&sigio_set);
sigaddset (&sigio_set, SIGIO);
sigprocmask (block ? SIG_BLOCK : SIG_UNBLOCK, &sigio_set, NULL);
#endif
}
> async_io_enabled = 0;
> #ifdef __QNX__
> nto_comctrl (0);
> @@ -852,12 +859,14 @@ disable_async_io (void)
> void
> initialize_async_io (void)
> {
> - /* Make sure that async I/O starts disabled. */
> + /* Install the signal handler. */
> +#ifndef USE_WIN32API
> + signal (SIGIO, input_interrupt);
> +#endif
> +
> + /* Make sure that async I/O starts blocked. */
> async_io_enabled = 1;
> disable_async_io ();
I think it's safer practice to block the signal before
installing the handler.
Otherwise LGTM.
> -
> - /* Make sure the signal is unblocked. */
> - unblock_async_io ();
> }
>
> /* Internal buffer used by readchar.
>
Thanks,
Pedro Alves
next prev parent reply other threads:[~2016-01-26 12:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-22 16:29 [PATCH] Fix fail in gdb.base/interrupt-noterm.exp Yao Qi
2016-01-22 16:47 ` Pedro Alves
2016-01-22 17:14 ` Yao Qi
2016-01-22 17:35 ` Pedro Alves
2016-01-22 18:30 ` Pedro Alves
2016-01-25 9:30 ` Yao Qi
2016-01-25 10:43 ` Pedro Alves
2016-01-26 9:59 ` [PATCH 0/2 V2] Fix a " Yao Qi
2016-01-26 9:59 ` [PATCH 2/2] [GDBserver] Block and unblock SIGIO Yao Qi
2016-01-26 12:01 ` Pedro Alves [this message]
2016-01-26 13:55 ` Yao Qi
2016-01-26 9:59 ` [PATCH 1/2] [GDBserver] Check input interrupt after reading in a packet Yao Qi
2016-01-26 11:42 ` Pedro Alves
2016-01-26 13:53 ` Yao Qi
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=56A76003.1010308@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
/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