From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 104002 invoked by alias); 26 Jan 2016 12:01:11 -0000 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 Received: (qmail 103854 invoked by uid 89); 26 Jan 2016 12:01:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2350, controlc, control-c, Control-C X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 26 Jan 2016 12:01:09 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8B7B091E86; Tue, 26 Jan 2016 12:01:08 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0QC17wF019461; Tue, 26 Jan 2016 07:01:07 -0500 Message-ID: <56A76003.1010308@redhat.com> Date: Tue, 26 Jan 2016 12:01:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] [GDBserver] Block and unblock SIGIO References: <86powqqa57.fsf@gmail.com> <1453802339-20401-1-git-send-email-yao.qi@linaro.org> <1453802339-20401-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1453802339-20401-3-git-send-email-yao.qi@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-01/txt/msg00646.txt.bz2 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