gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-dev] [PATCH 4/6] Replaces deprecated usleep() with nanosleep()


From: Fred Wright
Subject: Re: [gpsd-dev] [PATCH 4/6] Replaces deprecated usleep() with nanosleep()-based alternative.
Date: Fri, 9 Sep 2016 13:40:12 -0700 (PDT)

On Tue, 6 Sep 2016, Gary E. Miller wrote:

> No need.  usleep() was all removed in:
>
> commit e67e4118a0cbb5b5cecc62e7440299d0b5b35a37

True, but my way of removing it was better. :-)

> I don't think it is worth the overhead to wrap a basic POSIX 1993 call.

On the contrary, wrapping system calls so that they appear in only one
place is good practice in general, both to have one place to deal with any
portability tweaks, and to have one place to set a breakpoint on a given
call.  The intrinsic overhead of a system call is so large that the added
overhead of an extra function call is down in the noise (granted, not
entirely true if the call is implemented via a VDSO).  And worrying about
extra overhead on a function whose purpose is to waste time is pretty
pointless. :-)

In some programs, I've wrapped *all* system calls in local functions, and
accessed those functions through a vector table, so that the entire
program can be sandboxed for unit testing, without resorting to
platform-specific means of intercepting system calls.

Having multiple places that convert a scalar sleep value to a struct
timespec violates the DRY principle of good programming practice.  See:

        https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

But I'm not going to worry about pushing this right now.

Fred Wright



reply via email to

[Prev in Thread] Current Thread [Next in Thread]