On Thu, Jul 25, 2019 at 08:33:25AM -0600, Todd C. Miller wrote:
> On Wed, 24 Jul 2019 19:05:16 -0500, Scott Cheloha wrote:
> 
> > We can simplify the itimerdecr() code with the sys/time.h macros.
> > I think this is a lot easier to decipher.
> >
> > With the macros we don't need special logic to correctly handle the
> > reload if the decrement exceeds the time remaining in the itimer.
> >
> > With the loop we now correctly handle decrements larger than our
> > interval.  Maybe someone can make use of that.  Using the loop instead
> > of just an if-clause doesn't complicate our code so I figure we might
> > as well do the right thing in that case.
> 
> This looks correct and is much shorter.  I do find mixing explicit
> checks of tv_sec with timerisset a little confusing, but maybe that
> is just me.
> 
> For example, instead of this:
> 
>     if (itp->it_value.tv_sec >= 0 && timerisset(&itp->it_value))
> 
> I find the following easier to read:
> 
>     if (itp->it_value.tv_sec >= 0 && itp->it_value.tv_usec > 0)
> 
> (yes, I know the tv_usec could just be != 0).

I've been thinking for a while about adding another macro to sys/time.h
to handle this very common case, "timerisexpired":

#define timerisexpired(tv) ((tv)->tv_sec < 0 || !timerisset((tv)))

for chipping away at relative timeouts.  Then we could write

        if (!timerisexpired(&itp->it_value))

... which is precisely what we want to express.

But there aren't loads of bugs caused by people miswriting this check
so it's still on the drawing board.

Absent that I think yours reads better.

Reply via email to