Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Add proper check for clock_gettime #42206

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/mono/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,28 @@ if test x$host_win32 = xno; then
[#include <sys/types.h>])

dnl hires monotonic clock support
AC_SEARCH_LIBS(clock_gettime, rt)

# Check for clock_gettime
if test x$target_osx = xyes; then
# On OSX, clock_gettime is only really available on 10.12 or later
# However, it exists as a weak symbol on earlier versions, so hard-code a version check
AC_MONO_APPLE_AVAILABLE(clock_gettime_available, [whether clock_gettime is available on OSX],
[(MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)])
if test x$clock_gettime_available = xyes; then
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [clock_gettime])
fi
else
AC_CHECK_FUNC(clock_gettime, [
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [clock_gettime])
], [
# Old glibc (< 2.17) has clock_gettime in librt, so check there too
AC_CHECK_LIB(rt, clock_gettime, [
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [clock_gettime])
LIBS="$LIBS -lrt"
])
])
fi

AC_CHECK_FUNCS(clock_nanosleep)

dnl dynamic loader support
Expand Down
6 changes: 5 additions & 1 deletion src/mono/mono/utils/mono-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,17 @@ mono_clock_cleanup (mono_clock_id_t clk_id)

guint64
mono_clock_get_time_ns (mono_clock_id_t clk_id)
{
{
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;

if (clock_gettime (clk_id, &ts) == -1)
g_error ("%s: clock_gettime () returned -1, errno = %d", __func__, errno);

return ((guint64) ts.tv_sec * 1000000000) + (guint64) ts.tv_nsec;
#else
return 0;
#endif
}

#else
Expand Down