[vlc-devel] [PATCH 3/3] compat: add clock_getres for darwin

Thomas Guillem thomas at gllm.fr
Tue Mar 10 13:05:37 CET 2020


Good job !

LGTM for the set (after addressing my comment on patch 2/3).

On Tue, Mar 10, 2020, at 10:50, Marvin Scholz wrote:
> ---
>  compat/clock_getres.c | 57 +++++++++++++++++++++++++++++++++++++++++++
>  configure.ac          |  5 ++--
>  include/vlc_fixups.h  |  3 +++
>  3 files changed, 63 insertions(+), 2 deletions(-)
>  create mode 100644 compat/clock_getres.c
> 
> diff --git a/compat/clock_getres.c b/compat/clock_getres.c
> new file mode 100644
> index 0000000000..e39f97a61f
> --- /dev/null
> +++ b/compat/clock_getres.c
> @@ -0,0 +1,57 @@
> +/*****************************************************************************
> + * clock_getres.c: POSIX clock_getres() replacement
> + 
> *****************************************************************************
> + * Copyright © 2020 VLC authors and VideoLAN
> + *
> + * Author: Marvin Scholz <epirat07 at gmail dot com>
> + *
> + * This program is free software; you can redistribute it and/or 
> modify it
> + * under the terms of the GNU Lesser General Public License as 
> published by
> + * the Free Software Foundation; either version 2.1 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public 
> License
> + * along with this program; if not, write to the Free Software 
> Foundation,
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> + 
> *****************************************************************************/
> +
> +#ifndef __APPLE__
> +# error clock_getres not implemented on your platform!
> +#endif
> +
> +#ifdef HAVE_CONFIG_H
> +# include <config.h>
> +#endif
> +
> +#define _DARWIN_C_SOURCE
> +#define _POSIX_C_SOURCE  200809L
> +
> +#include <sys/errno.h>
> +#include <sys/types.h>
> +#include <sys/time.h>
> +#include <mach/clock_types.h>
> +
> +int clock_getres(clockid_t clock_id, struct timespec *tp)
> +{
> +    switch (clock_id) {
> +        case CLOCK_MONOTONIC:
> +        case CLOCK_REALTIME:
> +            // For realtime, it is using gettimeofday and for
> +            // the monotonic time it is relative to the system
> +            // boot time. Both of these use timeval, which has
> +            // nanosecond precision only.
> +            tp->tv_sec = 0;
> +            tp->tv_nsec = NSEC_PER_USEC;
> +            break;
> +        default:
> +            errno = EINVAL;
> +            return -1;
> +    }
> +
> +    return 0;
> +}
> diff --git a/configure.ac b/configure.ac
> index c20ab3c75c..3636c5a269 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -179,11 +179,12 @@ case "${host_os}" in
>      VLC_ADD_LIBS([libvlc 
> vlc],[-Wl,-undefined,dynamic_lookup,-framework,AppKit])
>      
> VLC_ADD_LIBS([libvlccore],[-Wl,-framework,CoreFoundation,-framework,CoreServices])
>  
> -    dnl macOS 10.11 lacks clock_gettime, introduced with 10.12
> +    dnl macOS 10.11 lacks clock_gettime and clock_getres, introduced with 10.12
>      AC_LIBOBJ([clock_gettime])
> +    AC_LIBOBJ([clock_getres])
>      dnl macOS lacks clock_nanosleep
>      AC_LIBOBJ([clock_nanosleep])
> -    AC_CHECK_FUNCS([clock_gettime clock_nanosleep])
> +    AC_CHECK_FUNCS([clock_gettime clock_getres clock_nanosleep])
>  
>      AC_EGREP_CPP(yes,
>              [#import <TargetConditionals.h>
> diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
> index a296db0c32..25c7de473e 100644
> --- a/include/vlc_fixups.h
> +++ b/include/vlc_fixups.h
> @@ -672,6 +672,9 @@ FILE *vlc_win32_tmpfile(void);
>  # ifndef HAVE_CLOCK_GETTIME
>  int clock_gettime(clockid_t clock_id, struct timespec *tp);
>  # endif
> +# ifndef HAVE_CLOCK_GETRES
> +int clock_getres(clockid_t clock_id, struct timespec *tp);
> +# endif
>  # ifndef HAVE_CLOCK_NANOSLEEP
>  int clock_nanosleep(clockid_t clock_id, int flags,
>          const struct timespec *rqtp, struct timespec *rmtp);
> -- 
> 2.21.1 (Apple Git-122.3)
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list