Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Cc: teawater@gmail.com, luis_gustavo@mentor.com
Subject: Re: [PATCH 3/5] Linux waitpid/__WALL emulation wrapper: If WNOHANG is set, don't touch sigprocmask.
Date: Thu, 27 Feb 2014 14:47:00 -0000	[thread overview]
Message-ID: <530F4FE8.1010006@redhat.com> (raw)
In-Reply-To: <1390486209-8167-3-git-send-email-palves@redhat.com>

On 01/23/2014 02:10 PM, Pedro Alves wrote:
> So the caller can use waitpid WNOHANG+sigsuspend.  Otherwise,
> my_waitpid lets the SIGCHLD handler run by mistake.

Sorry, that rationale was bogus.  I've pushed this in, but
as an optimization.

---
[PATCH] Linux waitpid/__WALL emulation wrapper: If WNOHANG is set,
 don't touch sigprocmask.

Just a small optimization.  No need to block/unblock signals if we're
not going to call sigsuspend.

gdb/
2014-02-27  Pedro Alves  <palves@redhat.com>

	* nat/linux-waitpid.c (my_waitpid): Only block signals if WNOHANG
	isn't set.
---
 gdb/ChangeLog           |  5 +++++
 gdb/nat/linux-waitpid.c | 21 +++++++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bb5f5aa..6cfb9c5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2014-02-27  Pedro Alves  <palves@redhat.com>
 
+	* nat/linux-waitpid.c (my_waitpid): Only block signals if WNOHANG
+	isn't set.
+
+2014-02-27  Pedro Alves  <palves@redhat.com>
+
 	PR 12702
 	* linux-nat.c (status_to_str): Moved to nat/linux-waitpid.c.
 	* nat/linux-waitpid.c: Include string.h.
diff --git a/gdb/nat/linux-waitpid.c b/gdb/nat/linux-waitpid.c
index e9e69db..4693120 100644
--- a/gdb/nat/linux-waitpid.c
+++ b/gdb/nat/linux-waitpid.c
@@ -92,15 +92,19 @@ my_waitpid (int pid, int *status, int flags)
 
       wnohang = (flags & WNOHANG) != 0;
       flags &= ~(__WALL | __WCLONE);
-      flags |= WNOHANG;
 
-      /* Block all signals while here.  This avoids knowing about
-	 LinuxThread's signals.  */
-      sigfillset (&block_mask);
-      sigprocmask (SIG_BLOCK, &block_mask, &org_mask);
+      if (!wnohang)
+	{
+	  flags |= WNOHANG;
+
+	  /* Block all signals while here.  This avoids knowing about
+	     LinuxThread's signals.  */
+	  sigfillset (&block_mask);
+	  sigprocmask (SIG_BLOCK, &block_mask, &org_mask);
 
-      /* ... except during the sigsuspend below.  */
-      sigemptyset (&wake_mask);
+	  /* ... except during the sigsuspend below.  */
+	  sigemptyset (&wake_mask);
+	}
 
       while (1)
 	{
@@ -129,7 +133,8 @@ my_waitpid (int pid, int *status, int flags)
 	  flags ^= __WCLONE;
 	}
 
-      sigprocmask (SIG_SETMASK, &org_mask, NULL);
+      if (!wnohang)
+	sigprocmask (SIG_SETMASK, &org_mask, NULL);
     }
   else
     {
-- 
1.7.11.7



  reply	other threads:[~2014-02-27 14:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-20 10:00 [PATCH] Fix PR 12702 - gdb can hang waiting for thread group leader (gdbserver) Hui Zhu
2013-07-24 18:25 ` Pedro Alves
2013-11-19  6:19   ` Hui Zhu
2014-01-23 14:51     ` Pedro Alves
2014-01-23 14:10       ` [PATCH 1/5] Move ptid_match to common/ptid.c Pedro Alves
2014-01-23 14:10         ` [PATCH 4/5] Teach gdbserver's linux backend about no unwaited-for children (TARGET_WAITDKIND_NO_RESUMED) Pedro Alves
2014-01-23 14:10         ` [PATCH 5/5] Add TARGET_WAITKIND_NO_RESUMED support to the RSP Pedro Alves
2014-01-23 14:10         ` [PATCH 3/5] Linux waitpid/__WALL emulation wrapper: If WNOHANG is set, don't touch sigprocmask Pedro Alves
2014-02-27 14:47           ` Pedro Alves [this message]
2014-01-23 14:10         ` [PATCH 2/5] Move status_to_str to nat/linux-waitpid.c Pedro Alves
2014-02-27 14:38       ` [PATCH] Fix PR 12702 - gdb can hang waiting for thread group leader (gdbserver) Pedro Alves
2014-02-27 14:54         ` Luis Machado

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=530F4FE8.1010006@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis_gustavo@mentor.com \
    --cc=teawater@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