[prev in list] [next in list] [prev in thread] [next in thread] 

List:       uclibc
Subject:    Re: [PATCH] bits/waitstatus.h: correctly interpret status 0x007f
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2013-06-29 13:17:20
Message-ID: 201306291517.20884.vda.linux () googlemail ! com
[Download RAW message or body]

On Friday 28 June 2013 23:51, James Hogan wrote:
> On 28 June 2013 22:16, Denys Vlasenko <vda.linux@googlemail.com> wrote:
> > I'm not sure we really want this (it adds double evaluation in WIFSTOPPED macro),
> > but this waitpid status does happen on MIPS.
> >
> > Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
> 
> This patch looks correct and optimal to me.

> >  /* Nonzero if STATUS indicates the child is stopped.  */
> > -#define        __WIFSTOPPED(status)    (((status) & 0xff) == 0x7f)
> > +#define        __WIFSTOPPED(status)    (((status) & 0xff) == 0x7f && ((status) & 0xff00))

I'm not sure about "optimal".
Here's another version, which compiles to one less branch:

+/* Nonzero if STATUS indicates the child is stopped.
+ * Low byte should be 0x7f and 2nd byte should be nonzero.
+ * The condition is true if both bytes have at least one set bit in the same
+ * position in bits 0-6, but at least one of 7th bits are clear
+ * (because we must not match 0xffff == WCONTINUED).
+ */
+#define        __WIFSTOPPED(status)    ((signed char)(((status) >> 8) & (status)) > 0)


It is also much less readable, so I needed to add a comment.

In any case, I propose that the new WIFSTOPPED macro must be conditional on NSIG > 126.
The old one is perfectly fine otherwise and should be used on 99.99999% of CPUs
out there which aren't MIPS.

-- 
vda
_______________________________________________
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic