mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
prefer clock_gettime
* configure.ac: clock_gettime or gettimeofday must exist. * process.c (rb_clock_gettime): prefer clock_gettime over gettimeofday, as the latter is obsolete in SUSv4. * random.c (fill_random_seed): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
93f7a11539
commit
a03ea378e7
4 changed files with 29 additions and 4 deletions
|
@ -2202,8 +2202,10 @@ AS_IF([test "$rb_cv_rshift_sign" = yes], [
|
||||||
AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>(int)(y)) : (x)>>(int)(y)))
|
AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>(int)(y)) : (x)>>(int)(y)))
|
||||||
])
|
])
|
||||||
|
|
||||||
AS_IF([test x"$ac_cv_func_gettimeofday" != xyes], [
|
AS_CASE(["$ac_cv_func_gettimeofday:$ac_cv_func_clock_gettime"],
|
||||||
AC_MSG_ERROR(gettimeofday() must exist)
|
[*yes*], [],
|
||||||
|
[
|
||||||
|
AC_MSG_ERROR(clock_gettime() or gettimeofday() must exist)
|
||||||
])
|
])
|
||||||
|
|
||||||
AS_IF([test "$ac_cv_func_sysconf" = yes], [
|
AS_IF([test "$ac_cv_func_sysconf" = yes], [
|
||||||
|
|
12
mjit.c
12
mjit.c
|
@ -222,10 +222,22 @@ static void remove_file(const char *filename);
|
||||||
static double
|
static double
|
||||||
real_ms_time(void)
|
real_ms_time(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
|
struct timespec tv;
|
||||||
|
# ifdef CLOCK_MONOTONIC
|
||||||
|
const clockid_t c = CLOCK_MONOTONIC;
|
||||||
|
# else
|
||||||
|
const clockid_t c = CLOCK_REALTIME;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
clock_gettime(c, &tv);
|
||||||
|
return tv.tv_nsec / 1000000.0 + tv.tv_sec * 1000.0;
|
||||||
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
return tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0;
|
return tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make and return copy of STR in the heap. */
|
/* Make and return copy of STR in the heap. */
|
||||||
|
|
|
@ -7340,8 +7340,9 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
if (SYMBOL_P(clk_id)) {
|
if (SYMBOL_P(clk_id)) {
|
||||||
/*
|
/*
|
||||||
* Non-clock_gettime clocks are provided by symbol clk_id.
|
* Non-clock_gettime clocks are provided by symbol clk_id.
|
||||||
*
|
*/
|
||||||
* gettimeofday is always available on platforms supported by Ruby.
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
|
/*
|
||||||
* GETTIMEOFDAY_BASED_CLOCK_REALTIME is used for
|
* GETTIMEOFDAY_BASED_CLOCK_REALTIME is used for
|
||||||
* CLOCK_REALTIME if clock_gettime is not available.
|
* CLOCK_REALTIME if clock_gettime is not available.
|
||||||
*/
|
*/
|
||||||
|
@ -7356,6 +7357,7 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
denominators[num_denominators++] = 1000000000;
|
denominators[num_denominators++] = 1000000000;
|
||||||
goto success;
|
goto success;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RUBY_TIME_BASED_CLOCK_REALTIME ID2SYM(id_TIME_BASED_CLOCK_REALTIME)
|
#define RUBY_TIME_BASED_CLOCK_REALTIME ID2SYM(id_TIME_BASED_CLOCK_REALTIME)
|
||||||
if (clk_id == RUBY_TIME_BASED_CLOCK_REALTIME) {
|
if (clk_id == RUBY_TIME_BASED_CLOCK_REALTIME) {
|
||||||
|
|
9
random.c
9
random.c
|
@ -558,15 +558,24 @@ static void
|
||||||
fill_random_seed(uint32_t *seed, size_t cnt)
|
fill_random_seed(uint32_t *seed, size_t cnt)
|
||||||
{
|
{
|
||||||
static int n = 0;
|
static int n = 0;
|
||||||
|
#if defined HAVE_CLOCK_GETTIME
|
||||||
|
struct timespec tv;
|
||||||
|
#elif defined HAVE_GETTIMEOFDAY
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
#endif
|
||||||
size_t len = cnt * sizeof(*seed);
|
size_t len = cnt * sizeof(*seed);
|
||||||
|
|
||||||
memset(seed, 0, len);
|
memset(seed, 0, len);
|
||||||
|
|
||||||
fill_random_bytes(seed, len, FALSE);
|
fill_random_bytes(seed, len, FALSE);
|
||||||
|
|
||||||
|
#if defined HAVE_CLOCK_GETTIME
|
||||||
|
clock_gettime(CLOCK_REALTIME, &tv);
|
||||||
|
seed[0] ^= tv.tv_nsec;
|
||||||
|
#elif defined HAVE_GETTIMEOFDAY
|
||||||
gettimeofday(&tv, 0);
|
gettimeofday(&tv, 0);
|
||||||
seed[0] ^= tv.tv_usec;
|
seed[0] ^= tv.tv_usec;
|
||||||
|
#endif
|
||||||
seed[1] ^= (uint32_t)tv.tv_sec;
|
seed[1] ^= (uint32_t)tv.tv_sec;
|
||||||
#if SIZEOF_TIME_T > SIZEOF_INT
|
#if SIZEOF_TIME_T > SIZEOF_INT
|
||||||
seed[0] ^= (uint32_t)((time_t)tv.tv_sec >> SIZEOF_INT * CHAR_BIT);
|
seed[0] ^= (uint32_t)((time_t)tv.tv_sec >> SIZEOF_INT * CHAR_BIT);
|
||||||
|
|
Loading…
Reference in a new issue