Skip to content

Commit

Permalink
Use the ID string for comparison in clock_gettime logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jun 30, 2018
1 parent 86736e3 commit 758cea5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyProcess.java
Expand Up @@ -1419,15 +1419,13 @@ public static IRubyObject times(Ruby runtime) {
Block.NULL_BLOCK);
}

// this is only in 2.1. See https://bugs.ruby-lang.org/issues/8658
@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject clock_gettime(ThreadContext context, IRubyObject self, IRubyObject _clock_id) {
Ruby runtime = context.runtime;

return makeClockResult(runtime, getTimeForClock(_clock_id, runtime), CLOCK_UNIT_FLOAT_SECOND);
}

// this is only in 2.1. See https://bugs.ruby-lang.org/issues/8658
@JRubyMethod(module = true, visibility = PRIVATE)
public static IRubyObject clock_gettime(ThreadContext context, IRubyObject self, IRubyObject _clock_id, IRubyObject _unit) {
Ruby runtime = context.runtime;
Expand All @@ -1451,9 +1449,10 @@ private static long getTimeForClock(IRubyObject _clock_id, Ruby runtime) throws
long nanos;

if (_clock_id instanceof RubySymbol) {
if (_clock_id.toString().equals(CLOCK_MONOTONIC)) {
RubySymbol clock_id = (RubySymbol) _clock_id;
if (clock_id.idString().equals(CLOCK_MONOTONIC)) {
nanos = System.nanoTime();
} else if (_clock_id.toString().equals(CLOCK_REALTIME)) {
} else if (clock_id.idString().equals(CLOCK_REALTIME)) {
POSIX posix = runtime.getPosix();
if (posix.isNative()) {
Timeval tv = posix.allocateTimeval();
Expand All @@ -1479,9 +1478,10 @@ private static long getResolutionForClock(IRubyObject _clock_id, Ruby runtime) t
long nanos;

if (_clock_id instanceof RubySymbol) {
if (_clock_id.toString().equals(CLOCK_MONOTONIC)) {
RubySymbol clock_id = (RubySymbol) _clock_id;
if (clock_id.idString().equals(CLOCK_MONOTONIC)) {
nanos = 1;
} else if (_clock_id.toString().equals(CLOCK_REALTIME)) {
} else if (clock_id.idString().equals(CLOCK_REALTIME)) {
nanos = 1000000;
} else {
throw runtime.newErrnoEINVALError("clock_gettime");
Expand Down

0 comments on commit 758cea5

Please sign in to comment.