ref: a52459b3e5a924f9a79e9b76998dd9a87a52b79a
parent: cf4b381ac772978b3179657475b9fdfb8b17c629
author: Jan Beich <jbeich@FreeBSD.org>
date: Mon Jul 29 14:37:33 EDT 2019
checkasm: replace gettimeofday with clock_gettime tests/checkasm/checkasm.c:55:5: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration] gettimeofday(&tv, NULL); ^
--- a/meson.build
+++ b/meson.build
@@ -113,11 +113,23 @@
# On Windows, we use a compatibility layer to emulate pthread
thread_dependency = []
thread_compat_dep = declare_dependency(sources : files('src/win32/thread.c'))
+
+ rt_dependency = []
else
thread_dependency = dependency('threads')
thread_compat_dep = []
-endif
+ rt_dependency = []
+ if cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args)
+ cdata.set('HAVE_CLOCK_GETTIME', 1)
+ else
+ rt_dependency = cc.find_library('rt', required: false)
+ if not cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args, dependencies : rt_dependency)
+ error('clock_gettime not found')
+ endif
+ cdata.set('HAVE_CLOCK_GETTIME', 1)
+ endif
+endif
# Header checks
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -45,15 +45,24 @@
#else
#include <unistd.h>
#include <signal.h>
-#include <sys/time.h>
+#include <time.h>
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+#endif
#define COLOR_RED 1
#define COLOR_GREEN 2
#define COLOR_YELLOW 3
static unsigned get_seed(void) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (unsigned) (tv.tv_usec + tv.tv_sec * 1000000);
+#ifdef __APPLE__
+ mach_timebase_info_data_t info;
+ mach_timebase_info(&info);
+ return (unsigned) (mach_absolute_time() * info.numer / info.denom);
+#elif defined(HAVE_CLOCK_GETTIME)
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (unsigned) (1000000000ULL * ts.tv_sec + ts.tv_nsec);
+#endif
}
#endif
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -90,7 +90,7 @@
include_directories: dav1d_inc_dirs,
c_args: [stackalign_flag, stackrealign_flag],
build_by_default: false,
- dependencies : [thread_dependency, m_lib],
+ dependencies : [thread_dependency, rt_dependency, m_lib],
)
test('checkasm', checkasm, is_parallel: false)
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -69,19 +69,6 @@
# Configuratin data for cli_config.h
cli_cdata = configuration_data()
-rt_dependency = []
-if host_machine.system() != 'windows'
- if cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args)
- cli_cdata.set('HAVE_CLOCK_GETTIME', 1)
- else
- rt_dependency = cc.find_library('rt', required: false)
- if not cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args, dependencies : rt_dependency)
- error('clock_gettime not found')
- endif
- cli_cdata.set('HAVE_CLOCK_GETTIME', 1)
- endif
-endif
-
cli_config_h_target = configure_file(output: 'cli_config.h', configuration: cli_cdata)
# dav1d cli tool sources