Skip to content

Commit

Permalink
runtime: Use clock_gettime to get current time.
Browse files Browse the repository at this point in the history
Fetch the current time in nanoseconds, not microseconds, by using
clock_gettime rather than gettimeofday.

Update golang/go#11222.

Fixes https://gcc.gnu.org/PR66574.

Change-Id: Ia9596f6a4b301ac0aa3b311e91106d0b9952ec3f
Reviewed-on: https://go-review.googlesource.com/17156
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
ianlancetaylor committed Nov 21, 2015
1 parent f79db38 commit b839c8c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
56 changes: 56 additions & 0 deletions libgo/configure
Original file line number Diff line number Diff line change
Expand Up @@ -14477,6 +14477,62 @@ ac_res=$ac_cv_search_nanosleep
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing clock_gettime" >&5
$as_echo_n "checking for library containing clock_gettime... " >&6; }
if test "${ac_cv_search_clock_gettime+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char clock_gettime ();
int
main ()
{
return clock_gettime ();
;
return 0;
}
_ACEOF
for ac_lib in '' rt; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_clock_gettime=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if test "${ac_cv_search_clock_gettime+set}" = set; then :
break
fi
done
if test "${ac_cv_search_clock_gettime+set}" = set; then :

else
ac_cv_search_clock_gettime=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clock_gettime" >&5
$as_echo "$ac_cv_search_clock_gettime" >&6; }
ac_res=$ac_cv_search_clock_gettime
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"

fi


Expand Down
3 changes: 2 additions & 1 deletion libgo/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,10 @@ PTHREAD_LIBS=
AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS=-lpthread)
AC_SUBST(PTHREAD_LIBS)

dnl Test if -lrt is required for sched_yield and/or nanosleep.
dnl Test if -lrt is required for sched_yield or nanosleep or clock_gettime.
AC_SEARCH_LIBS([sched_yield], [rt])
AC_SEARCH_LIBS([nanosleep], [rt])
AC_SEARCH_LIBS([clock_gettime], [rt])

AC_C_BIGENDIAN

Expand Down
8 changes: 4 additions & 4 deletions libgo/runtime/go-now.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
struct time_now_ret
now()
{
struct timeval tv;
struct timespec ts;
struct time_now_ret ret;

gettimeofday (&tv, NULL);
ret.sec = tv.tv_sec;
ret.nsec = tv.tv_usec * 1000;
clock_gettime (CLOCK_REALTIME, &ts);
ret.sec = ts.tv_sec;
ret.nsec = ts.tv_nsec;
return ret;
}

0 comments on commit b839c8c

Please sign in to comment.