mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* process.c (unsigned_clock_t): Defined.
(rb_clock_gettime): Consider clock_t overflow for ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID. * configure.in: Check the size of clock_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5a87332ef9
commit
3873e09cad
3 changed files with 24 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
|||
Thu Aug 22 20:14:59 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* process.c (unsigned_clock_t): Defined.
|
||||
(rb_clock_gettime): Consider clock_t overflow for
|
||||
ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID.
|
||||
|
||||
* configure.in: Check the size of clock_t.
|
||||
|
||||
Thu Aug 22 16:22:48 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* compile.c (build_postexe_iseq): fix to setup the local table.
|
||||
|
|
|
@ -1168,6 +1168,7 @@ RUBY_CHECK_SIZEOF(void*, [int long "long long"], [ILP LP LLP])
|
|||
RUBY_CHECK_SIZEOF(float)
|
||||
RUBY_CHECK_SIZEOF(double)
|
||||
RUBY_CHECK_SIZEOF(time_t, [long "long long"], [], [@%:@include <time.h>])
|
||||
RUBY_CHECK_SIZEOF(clock_t)
|
||||
|
||||
AC_DEFUN([RUBY_CHECK_PRINTF_PREFIX], [
|
||||
AC_CACHE_CHECK([for printf prefix for $1], [rb_cv_pri_prefix_]AS_TR_SH($1),[
|
||||
|
|
19
process.c
19
process.c
|
@ -196,6 +196,14 @@ static rb_gid_t obj2gid(VALUE id);
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if SIZEOF_CLOCK_T == SIZEOF_INT
|
||||
typedef unsigned int unsigned_clock_t;
|
||||
#elif SIZEOF_CLOCK_T == SIZEOF_LONG
|
||||
typedef unsigned long unsigned_clock_t;
|
||||
#elif defined(HAVE_LONG_LONG) && SIZEOF_CLOCK_T == SIZEOF_LONG_LONG
|
||||
typedef unsigned LONG_LONG unsigned_clock_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* Process.pid -> fixnum
|
||||
|
@ -6886,15 +6894,18 @@ rb_clock_gettime(int argc, VALUE *argv)
|
|||
#define RUBY_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
||||
ID2SYM(rb_intern("ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
||||
if (clk_id == RUBY_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
||||
double ns;
|
||||
double s, ns;
|
||||
clock_t c;
|
||||
unsigned_clock_t uc;
|
||||
c = clock();
|
||||
errno = 0;
|
||||
if (c == (clock_t)-1)
|
||||
rb_sys_fail("clock");
|
||||
ns = c * (1e9 / CLOCKS_PER_SEC);
|
||||
ts.tv_sec = (time_t)(ns*1e-9);
|
||||
ts.tv_nsec = ns - ts.tv_sec*1e9;
|
||||
uc = (unsigned_clock_t)c;
|
||||
ns = (uc*1e9) / CLOCKS_PER_SEC; /* uc*1e9 doesn't lose data if clock_t is 32bit. */
|
||||
s = floor(ns*1e-9);
|
||||
ts.tv_sec = (time_t)s;
|
||||
ts.tv_nsec = ns - s*1e9;
|
||||
goto success;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue