[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] [PATCH 4/6] Replaces deprecated usleep() with nanosleep()
From: |
Gary E. Miller |
Subject: |
Re: [gpsd-dev] [PATCH 4/6] Replaces deprecated usleep() with nanosleep()-based alternative. |
Date: |
Tue, 6 Sep 2016 17:29:35 -0700 |
Yo Fred!
No need. usleep() was all removed in:
commit e67e4118a0cbb5b5cecc62e7440299d0b5b35a37
I don't think it is worth the overhead to wrap a basic POSIX 1993 call.
On Mon, 5 Sep 2016 18:09:26 -0700
Fred Wright <address@hidden> wrote:
> This creates a new gps_usleep() function, which is a drop-in
> replacement for usleep(). Although it now uses nanosleep()
> unconditionally, this single function could be switched back
> to usleep() if needed for any targets.
>
> This change only fixes the main gpsd components, leaving the
> contrib/ fixes for a followup.
>
> TESTED:
> Ran "scons build-all check" under OSX. This change is not expected
> to be OS-dependent as it stands.
> ---
> SConstruct | 1 +
> driver_garmin.c | 2 +-
> drivers.c | 4 ++--
> gps_usleep.c | 23 +++++++++++++++++++++++
> gpsctl.c | 2 +-
> gpsd.c | 2 +-
> gpsd.h-tail | 3 +++
> gpsmon.c | 4 ++--
> libgps.h | 3 +++
> ntpshmmon.c | 4 +++-
> serial.c | 2 +-
> 11 files changed, 41 insertions(+), 9 deletions(-)
> create mode 100644 gps_usleep.c
>
> diff --git a/SConstruct b/SConstruct
> index a5be834..1a5c1cf 100644
> --- a/SConstruct
> +++ b/SConstruct
> @@ -1068,6 +1068,7 @@ libgps_sources = [
> "gpsutils.c",
> "gpsdclient.c",
> "gps_maskdump.c",
> + "gps_usleep.c",
> "hex.c",
> "json.c",
> "libgps_core.c",
> diff --git a/driver_garmin.c b/driver_garmin.c
> index c80b842..9f1788a 100644
> --- a/driver_garmin.c
> +++ b/driver_garmin.c
> @@ -1158,7 +1158,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t
> *session)
> // sending ACK too soon might hang the session
> // so send ACK last, after a pause
> - (void)usleep(300);
> + (void)gps_usleep(300);
> Send_ACK();
> gpsd_log(&session->context->errout, LOG_DATA,
> "Garmin: garmin_ser_parse( )\n");
> diff --git a/drivers.c b/drivers.c
> index 85b12a9..eaafe63 100644
> --- a/drivers.c
> +++ b/drivers.c
> @@ -290,7 +290,7 @@ static void garmin_mode_switch(struct
> gps_device_t *session, int mode) if (mode == MODE_BINARY) {
> (void)nmea_send(session, "$PGRMC1,1,2,1,,,,2,W,N");
> (void)nmea_send(session, "$PGRMI,,,,,,,R");
> - (void)usleep(333); /* standard Garmin settling time */
> + (void)gps_usleep(333); /* standard Garmin settling
> time */ }
> }
> #endif /* RECONFIGURE_ENABLE */
> @@ -607,7 +607,7 @@ static void earthmate_event_hook(struct
> gps_device_t *session, event_t event) return;
> if (event == event_triggermatch) {
> (void)gpsd_write(session, "EARTHA\r\n", 8);
> - (void)usleep(10000);
> + (void)gps_usleep(10000);
> (void)gpsd_switch_driver(session, "Zodiac");
> }
> }
> diff --git a/gps_usleep.c b/gps_usleep.c
> new file mode 100644
> index 0000000..fd526d2
> --- /dev/null
> +++ b/gps_usleep.c
> @@ -0,0 +1,23 @@
> +/*
> + * Replacement for deprecated usleep()
> + *
> + * This file is Copyright (c) 2016 by the GPSD project
> + * BSD terms apply: see the file COPYING in the distribution root
> for details.
> + */
> +
> +#include <time.h>
> +
> +#include "libgps.h" /* For prototype */
> +
> +/*
> + * Note that this is the only place that would need to be modified
> to go
> + * back to using usleep() if needed.
> + */
> +
> +int gps_usleep(unsigned int useconds)
> +{
> + struct timespec delay = { .tv_sec = useconds / 1000000,
> + .tv_nsec = useconds % 1000000 * 1000};
> +
> + return nanosleep(&delay, NULL);
> +}
> diff --git a/gpsctl.c b/gpsctl.c
> index e3835bd..34d2e56 100644
> --- a/gpsctl.c
> +++ b/gpsctl.c
> @@ -47,7 +47,7 @@ static void settle(struct gps_device_t *session)
> * See the 'deep black magic' comment in serial.c:set_serial().
> */
> (void)tcdrain(session->gpsdata.gps_fd);
> - (void)usleep(50000);
> + (void)gps_usleep(50000);
> (void)tcdrain(session->gpsdata.gps_fd);
> }
> #endif /* defined(RECONFIGURE_ENABLE) || defined(CONTROLSEND_ENABLE)
> */ diff --git a/gpsd.c b/gpsd.c
> index 726cba4..626ab64 100644
> --- a/gpsd.c
> +++ b/gpsd.c
> @@ -1042,7 +1042,7 @@ static void set_serial(struct gps_device_t
> *device,
> * across any given type of UART.
> */
> (void)tcdrain(device->gpsdata.gps_fd);
> - (void)usleep(50000);
> + (void)gps_usleep(50000);
> gpsd_set_speed(device, speed, parity, stopbits);
> }
> }
> diff --git a/gpsd.h-tail b/gpsd.h-tail
> index d1fb5ea..e075cf1 100644
> --- a/gpsd.h-tail
> +++ b/gpsd.h-tail
> @@ -980,6 +980,9 @@ void cfmakeraw(struct termios *);
>
> #define DEVICEHOOKPATH "/"SYSCONFDIR"/gpsd/device-hook"
>
> +/* System call helpers */
> +extern int gps_usleep(unsigned int useconds);
> +
> # ifdef __cplusplus
> }
> # endif
> diff --git a/gpsmon.c b/gpsmon.c
> index ee4aaeb..7e469db 100644
> --- a/gpsmon.c
> +++ b/gpsmon.c
> @@ -963,7 +963,7 @@ static bool do_command(const char *line)
> switcher->mode_switcher(&session, (int)v);
> context.readonly = true;
> (void)tcdrain(session.gpsdata.gps_fd);
> - (void)usleep(50000);
> + (void)gps_usleep(50000);
> /*
> * Session device change will be set to NMEA when
> * gpsmon resyncs. So stash the current type to
> @@ -1035,7 +1035,7 @@ static bool do_command(const char *line)
> * buffer.
> */
> (void)tcdrain(session.gpsdata.gps_fd);
> - (void)usleep(50000);
> + (void)gps_usleep(50000);
> (void)gpsd_set_speed(&session, speed,
> parity, stopbits);
> } else
> diff --git a/libgps.h b/libgps.h
> index 70d4b7d..610bbab 100644
> --- a/libgps.h
> +++ b/libgps.h
> @@ -41,6 +41,9 @@ extern int gps_dbus_mainloop(struct gps_data_t *,
> int, extern int json_ais_read(const char *, char *, size_t, struct
> ais_t *, const char **);
>
> +/* System call helpers */
> +extern int gps_usleep(unsigned int useconds);
> +
> /* debugging apparatus for the client library */
> #ifdef CLIENTDEBUG_ENABLE
> #define LIBGPS_DEBUG
> diff --git a/ntpshmmon.c b/ntpshmmon.c
> index 8706f41..1bdf2d2 100644
> --- a/ntpshmmon.c
> +++ b/ntpshmmon.c
> @@ -17,6 +17,8 @@
> #include "revision.h"
> #include "timespec.h"
>
> +extern int gps_usleep(unsigned int useconds);
> +
> #define NTPSEGMENTS 256 /* NTPx for x any byte */
>
> static struct shmTime *segments[NTPSEGMENTS + 1];
> @@ -173,7 +175,7 @@ int main(int argc, char **argv)
> break;
> }
> }
> - (void)usleep((useconds_t)1000);
> + (void)gps_usleep((useconds_t)1000);
> } while ( 0 < nsamples );
>
> exit(EXIT_SUCCESS);
> diff --git a/serial.c b/serial.c
> index 0a17007..5883930 100644
> --- a/serial.c
> +++ b/serial.c
> @@ -383,7 +383,7 @@ void gpsd_set_speed(struct gps_device_t *session,
> * occasional failure to lock.
> */
> (void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH);
> - (void)usleep(200000);
> + (void)gps_usleep(200000);
> (void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH);
> }
> gpsd_log(&session->context->errout, LOG_INF,
RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
address@hidden Tel:+1 541 382 8588
pgpr_t1jwloiT.pgp
Description: OpenPGP digital signature
[gpsd-dev] [PATCH 6/6] Eliminates the one use of the portability-challenged alloca()., Fred Wright, 2016/09/05
[gpsd-dev] [PATCH 2/6] bzero() is gone in POSIX 2008. Use memset(), Fred Wright, 2016/09/05