-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-18163] Use nanosecond precision for Kernel#sleep and Mutex#sleep (#…
…2716) PullRequest: truffleruby/3479
- Loading branch information
Showing
7 changed files
with
95 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 0 additions & 83 deletions
83
src/main/java/org/truffleruby/core/cast/DurationToMillisecondsNode.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
src/main/java/org/truffleruby/core/cast/DurationToNanoSecondsNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 2.0, or | ||
* GNU General Public License version 2, or | ||
* GNU Lesser General Public License version 2.1. | ||
*/ | ||
package org.truffleruby.core.cast; | ||
|
||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import org.truffleruby.language.RubyBaseNode; | ||
import org.truffleruby.language.NotProvided; | ||
import org.truffleruby.language.control.RaiseException; | ||
|
||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.profiles.ConditionProfile; | ||
import org.truffleruby.language.dispatch.DispatchNode; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public abstract class DurationToNanoSecondsNode extends RubyBaseNode { | ||
|
||
private final ConditionProfile durationLessThanZeroProfile = ConditionProfile.create(); | ||
|
||
public abstract long execute(Object duration); | ||
|
||
@Specialization | ||
protected long noDuration(NotProvided duration) { | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
@Specialization | ||
protected long duration(long duration) { | ||
return validate(TimeUnit.SECONDS.toNanos(duration)); | ||
} | ||
|
||
@Specialization | ||
protected long duration(double duration) { | ||
return validate((long) (duration * 1e9)); | ||
} | ||
|
||
@Fallback | ||
protected long duration(Object duration, | ||
@Cached DispatchNode durationToNanoSeconds, | ||
@Cached ToLongNode toLongNode) { | ||
final Object nanoseconds = durationToNanoSeconds.call( | ||
coreLibrary().truffleKernelOperationsModule, | ||
"convert_duration_to_nanoseconds", | ||
duration); | ||
return validate(toLongNode.execute(nanoseconds)); | ||
} | ||
|
||
private long validate(long durationInNanos) { | ||
if (durationLessThanZeroProfile.profile(durationInNanos < 0)) { | ||
throw new RaiseException(getContext(), coreExceptions().argumentErrorTimeIntervalPositive(this)); | ||
} | ||
return durationInNanos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters