Skip to content

Commit

Permalink
Implement Process.clock_gettime(real) using native gettimeofday.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 10, 2017
1 parent a47fd03 commit 046f2a1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/src/main/java/org/jruby/RubyProcess.java
Expand Up @@ -36,6 +36,7 @@
import jnr.ffi.byref.IntByReference;
import jnr.posix.RLimit;
import jnr.posix.Times;
import jnr.posix.Timeval;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
Expand Down Expand Up @@ -1449,7 +1450,14 @@ private static long getTimeForClock(IRubyObject _clock_id, Ruby runtime) throws
if (_clock_id.toString().equals(CLOCK_MONOTONIC)) {
nanos = System.nanoTime();
} else if (_clock_id.toString().equals(CLOCK_REALTIME)) {
nanos = System.currentTimeMillis() * 1000000;
POSIX posix = runtime.getPosix();
if (posix.isNative()) {
Timeval tv = posix.allocateTimeval();
posix.gettimeofday(tv);
nanos = tv.sec() * 1_000_000_000 + tv.usec() * 1000;
} else {
nanos = System.currentTimeMillis() * 1000000;
}
} else {
throw runtime.newErrnoEINVALError("clock_gettime");
}
Expand Down

0 comments on commit 046f2a1

Please sign in to comment.