mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* process.c (rb_clock_gettime): The emulated clock names changed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fb9b9b1862
commit
811eaddf4c
3 changed files with 38 additions and 34 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sat Aug 24 10:35:09 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* process.c (rb_clock_gettime): The emulated clock names changed.
|
||||||
|
|
||||||
Fri Aug 23 22:22:07 2013 Tanaka Akira <akr@fsij.org>
|
Fri Aug 23 22:22:07 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* process.c (rb_clock_gettime): Add a cast to fix compile error by
|
* process.c (rb_clock_gettime): Add a cast to fix compile error by
|
||||||
|
|
48
process.c
48
process.c
|
@ -6868,13 +6868,13 @@ make_clock_result(struct timetick *ttp,
|
||||||
* There are emulations for clock_gettime().
|
* There are emulations for clock_gettime().
|
||||||
*
|
*
|
||||||
* For example, Process::CLOCK_REALTIME is defined as
|
* For example, Process::CLOCK_REALTIME is defined as
|
||||||
* +:SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME+ when clock_gettime() is not available.
|
* +:GETTIMEOFDAY_BASED_CLOCK_REALTIME+ when clock_gettime() is not available.
|
||||||
*
|
*
|
||||||
* Emulations for +CLOCK_REALTIME+:
|
* Emulations for +CLOCK_REALTIME+:
|
||||||
* [:SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME]
|
* [:GETTIMEOFDAY_BASED_CLOCK_REALTIME]
|
||||||
* Use gettimeofday().
|
* Use gettimeofday().
|
||||||
* The resolution is 1 micro second.
|
* The resolution is 1 micro second.
|
||||||
* [:ISO_C_TIME_BASED_CLOCK_REALTIME]
|
* [:TIME_BASED_CLOCK_REALTIME]
|
||||||
* Use time().
|
* Use time().
|
||||||
* The resolution is 1 second.
|
* The resolution is 1 second.
|
||||||
*
|
*
|
||||||
|
@ -6883,12 +6883,12 @@ make_clock_result(struct timetick *ttp,
|
||||||
* The resolution is CPU dependent.
|
* The resolution is CPU dependent.
|
||||||
*
|
*
|
||||||
* Emulations for +CLOCK_PROCESS_CPUTIME_ID+:
|
* Emulations for +CLOCK_PROCESS_CPUTIME_ID+:
|
||||||
* [:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID]
|
* [:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID]
|
||||||
* Use getrusage() with RUSAGE_SELF.
|
* Use getrusage() with RUSAGE_SELF.
|
||||||
* getrusage() is defined by Single Unix Specification.
|
* getrusage() is defined by Single Unix Specification.
|
||||||
* The result is addition of ru_utime and ru_stime.
|
* The result is addition of ru_utime and ru_stime.
|
||||||
* The resolution is 1 micro second.
|
* The resolution is 1 micro second.
|
||||||
* [:POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID]
|
* [:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID]
|
||||||
* Use times() defined by POSIX.
|
* Use times() defined by POSIX.
|
||||||
* The result is addition of tms_utime and tms_stime.
|
* The result is addition of tms_utime and tms_stime.
|
||||||
* tms_cutime and tms_cstime are ignored.
|
* tms_cutime and tms_cstime are ignored.
|
||||||
|
@ -6896,7 +6896,7 @@ make_clock_result(struct timetick *ttp,
|
||||||
* "getconf CLK_TCK" command shows the clock ticks per second.
|
* "getconf CLK_TCK" command shows the clock ticks per second.
|
||||||
* (The clock ticks per second is defined by HZ macro in older systems.)
|
* (The clock ticks per second is defined by HZ macro in older systems.)
|
||||||
* If it is 100, the resolution is 10 milli second.
|
* If it is 100, the resolution is 10 milli second.
|
||||||
* [:ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID]
|
* [:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID]
|
||||||
* Use clock() defined by ISO C.
|
* Use clock() defined by ISO C.
|
||||||
* The resolution is 1/CLOCKS_PER_SEC.
|
* The resolution is 1/CLOCKS_PER_SEC.
|
||||||
* CLOCKS_PER_SEC is the C-level macro defined by time.h.
|
* CLOCKS_PER_SEC is the C-level macro defined by time.h.
|
||||||
|
@ -6952,11 +6952,11 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
* 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.
|
* gettimeofday is always available on platforms supported by Ruby.
|
||||||
* SUS_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.
|
||||||
*/
|
*/
|
||||||
#define RUBY_SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME ID2SYM(rb_intern("SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME"))
|
#define RUBY_GETTIMEOFDAY_BASED_CLOCK_REALTIME ID2SYM(rb_intern("GETTIMEOFDAY_BASED_CLOCK_REALTIME"))
|
||||||
if (clk_id == RUBY_SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME) {
|
if (clk_id == RUBY_GETTIMEOFDAY_BASED_CLOCK_REALTIME) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
ret = gettimeofday(&tv, 0);
|
ret = gettimeofday(&tv, 0);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
|
@ -6967,8 +6967,8 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
goto success;
|
goto success;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RUBY_ISO_C_TIME_BASED_CLOCK_REALTIME ID2SYM(rb_intern("ISO_C_TIME_BASED_CLOCK_REALTIME"))
|
#define RUBY_TIME_BASED_CLOCK_REALTIME ID2SYM(rb_intern("TIME_BASED_CLOCK_REALTIME"))
|
||||||
if (clk_id == RUBY_ISO_C_TIME_BASED_CLOCK_REALTIME) {
|
if (clk_id == RUBY_TIME_BASED_CLOCK_REALTIME) {
|
||||||
time_t t;
|
time_t t;
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
if (t == (time_t)-1)
|
if (t == (time_t)-1)
|
||||||
|
@ -6980,9 +6980,9 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RUSAGE_SELF
|
#ifdef RUSAGE_SELF
|
||||||
#define RUBY_SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
#define RUBY_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
||||||
ID2SYM(rb_intern("SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
ID2SYM(rb_intern("GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
||||||
if (clk_id == RUBY_SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
if (clk_id == RUBY_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
||||||
struct rusage usage;
|
struct rusage usage;
|
||||||
int32_t usec;
|
int32_t usec;
|
||||||
ret = getrusage(RUSAGE_SELF, &usage);
|
ret = getrusage(RUSAGE_SELF, &usage);
|
||||||
|
@ -7001,9 +7001,9 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TIMES
|
#ifdef HAVE_TIMES
|
||||||
#define RUBY_POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
#define RUBY_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
||||||
ID2SYM(rb_intern("POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
ID2SYM(rb_intern("TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
||||||
if (clk_id == RUBY_POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
if (clk_id == RUBY_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
||||||
struct tms buf;
|
struct tms buf;
|
||||||
unsigned_clock_t utime, stime;
|
unsigned_clock_t utime, stime;
|
||||||
if (times(&buf) == (clock_t)-1)
|
if (times(&buf) == (clock_t)-1)
|
||||||
|
@ -7021,9 +7021,9 @@ rb_clock_gettime(int argc, VALUE *argv)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define RUBY_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
#define RUBY_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID \
|
||||||
ID2SYM(rb_intern("ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
ID2SYM(rb_intern("CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID"))
|
||||||
if (clk_id == RUBY_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
if (clk_id == RUBY_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID) {
|
||||||
clock_t c;
|
clock_t c;
|
||||||
unsigned_clock_t uc;
|
unsigned_clock_t uc;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -7340,8 +7340,8 @@ Init_process(void)
|
||||||
|
|
||||||
#ifdef CLOCK_REALTIME
|
#ifdef CLOCK_REALTIME
|
||||||
rb_define_const(rb_mProcess, "CLOCK_REALTIME", CLOCKID2NUM(CLOCK_REALTIME));
|
rb_define_const(rb_mProcess, "CLOCK_REALTIME", CLOCKID2NUM(CLOCK_REALTIME));
|
||||||
#elif defined(RUBY_SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME)
|
#elif defined(RUBY_GETTIMEOFDAY_BASED_CLOCK_REALTIME)
|
||||||
rb_define_const(rb_mProcess, "CLOCK_REALTIME", RUBY_SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME);
|
rb_define_const(rb_mProcess, "CLOCK_REALTIME", RUBY_GETTIMEOFDAY_BASED_CLOCK_REALTIME);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CLOCK_MONOTONIC
|
#ifdef CLOCK_MONOTONIC
|
||||||
rb_define_const(rb_mProcess, "CLOCK_MONOTONIC", CLOCKID2NUM(CLOCK_MONOTONIC));
|
rb_define_const(rb_mProcess, "CLOCK_MONOTONIC", CLOCKID2NUM(CLOCK_MONOTONIC));
|
||||||
|
@ -7350,8 +7350,8 @@ Init_process(void)
|
||||||
#endif
|
#endif
|
||||||
#ifdef CLOCK_PROCESS_CPUTIME_ID
|
#ifdef CLOCK_PROCESS_CPUTIME_ID
|
||||||
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", CLOCKID2NUM(CLOCK_PROCESS_CPUTIME_ID));
|
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", CLOCKID2NUM(CLOCK_PROCESS_CPUTIME_ID));
|
||||||
#elif defined(RUBY_SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
|
#elif defined(RUBY_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
|
||||||
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", RUBY_SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID);
|
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", RUBY_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CLOCK_THREAD_CPUTIME_ID
|
#ifdef CLOCK_THREAD_CPUTIME_ID
|
||||||
rb_define_const(rb_mProcess, "CLOCK_THREAD_CPUTIME_ID", CLOCKID2NUM(CLOCK_THREAD_CPUTIME_ID));
|
rb_define_const(rb_mProcess, "CLOCK_THREAD_CPUTIME_ID", CLOCKID2NUM(CLOCK_THREAD_CPUTIME_ID));
|
||||||
|
|
|
@ -1681,20 +1681,20 @@ EOS
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clock_gettime_SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME
|
def test_clock_gettime_GETTIMEOFDAY_BASED_CLOCK_REALTIME
|
||||||
n = :SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME
|
n = :GETTIMEOFDAY_BASED_CLOCK_REALTIME
|
||||||
t = Process.clock_gettime(n)
|
t = Process.clock_gettime(n)
|
||||||
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clock_gettime_ISO_C_TIME_BASED_CLOCK_REALTIME
|
def test_clock_gettime_TIME_BASED_CLOCK_REALTIME
|
||||||
n = :ISO_C_TIME_BASED_CLOCK_REALTIME
|
n = :TIME_BASED_CLOCK_REALTIME
|
||||||
t = Process.clock_gettime(n)
|
t = Process.clock_gettime(n)
|
||||||
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clock_gettime_SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
|
def test_clock_gettime_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
|
||||||
n = :SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
|
n = :GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID
|
||||||
begin
|
begin
|
||||||
t = Process.clock_gettime(n)
|
t = Process.clock_gettime(n)
|
||||||
rescue Errno::EINVAL
|
rescue Errno::EINVAL
|
||||||
|
@ -1703,8 +1703,8 @@ EOS
|
||||||
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clock_gettime_POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
|
def test_clock_gettime_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
|
||||||
n = :POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
|
n = :TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
|
||||||
begin
|
begin
|
||||||
t = Process.clock_gettime(n)
|
t = Process.clock_gettime(n)
|
||||||
rescue Errno::EINVAL
|
rescue Errno::EINVAL
|
||||||
|
@ -1713,8 +1713,8 @@ EOS
|
||||||
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_clock_gettime_ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
|
def test_clock_gettime_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
|
||||||
n = :ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
|
n = :CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
|
||||||
t = Process.clock_gettime(n)
|
t = Process.clock_gettime(n)
|
||||||
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
assert_kind_of(Float, t, "Process.clock_gettime(:#{n})")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue