summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-21 08:34:48 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-21 08:34:48 +0000
commit873dd9bc4568a73202977ee1a5ac1dc2a7ff86fb (patch)
tree9fba4bbf2c43970126818fc8f723e0449715138a /gc.c
parent922467238e37c07d1eb6d383be0a177b4b13b82e (diff)
* gc.c (getrusage_time): Fallback clock_gettime to getrusage when
clock_gettime fails. Reported by Eric Saxby. [ruby-core:56762] [Bug #8805] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/gc.c b/gc.c
index 1e4c26a64d..2d469cfcdf 100644
--- a/gc.c
+++ b/gc.c
@@ -5059,43 +5059,54 @@ static double
getrusage_time(void)
{
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
- struct timespec ts;
-
- if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == 0) {
- return ts.tv_sec + ts.tv_nsec * 1e-9;
+ {
+ static int try_clock_gettime = 1;
+ struct timespec ts;
+ if (try_clock_gettime && clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == 0) {
+ return ts.tv_sec + ts.tv_nsec * 1e-9;
+ }
+ else {
+ try_clock_gettime = 0;
+ }
}
- return 0.0;
-#elif defined RUSAGE_SELF
- struct rusage usage;
- struct timeval time;
- getrusage(RUSAGE_SELF, &usage);
- time = usage.ru_utime;
- return time.tv_sec + time.tv_usec * 1e-6;
-#elif defined _WIN32
- FILETIME creation_time, exit_time, kernel_time, user_time;
- ULARGE_INTEGER ui;
- LONG_LONG q;
- double t;
-
- if (GetProcessTimes(GetCurrentProcess(),
- &creation_time, &exit_time, &kernel_time, &user_time) == 0)
+#endif
+
+#ifdef RUSAGE_SELF
{
- return 0.0;
+ struct rusage usage;
+ struct timeval time;
+ if (getrusage(RUSAGE_SELF, &usage) == 0) {
+ time = usage.ru_utime;
+ return time.tv_sec + time.tv_usec * 1e-6;
+ }
}
- memcpy(&ui, &user_time, sizeof(FILETIME));
- q = ui.QuadPart / 10L;
- t = (DWORD)(q % 1000000L) * 1e-6;
- q /= 1000000L;
+#endif
+
+#ifdef _WIN32
+ {
+ FILETIME creation_time, exit_time, kernel_time, user_time;
+ ULARGE_INTEGER ui;
+ LONG_LONG q;
+ double t;
+
+ if (GetProcessTimes(GetCurrentProcess(),
+ &creation_time, &exit_time, &kernel_time, &user_time) != 0) {
+ memcpy(&ui, &user_time, sizeof(FILETIME));
+ q = ui.QuadPart / 10L;
+ t = (DWORD)(q % 1000000L) * 1e-6;
+ q /= 1000000L;
#ifdef __GNUC__
- t += q;
+ t += q;
#else
- t += (double)(DWORD)(q >> 16) * (1 << 16);
- t += (DWORD)q & ~(~0 << 16);
+ t += (double)(DWORD)(q >> 16) * (1 << 16);
+ t += (DWORD)q & ~(~0 << 16);
#endif
- return t;
-#else
- return 0.0;
+ return t;
+ }
+ }
#endif
+
+ return 0.0;
}
static inline void