Search in sources :

Example 1 with Time.timespec

use of com.oracle.svm.core.posix.headers.Time.timespec in project graal by oracle.

the class PthreadConditionUtils method deadlineTimespecToDelayNanos.

@Uninterruptible(reason = "Called from uninterruptible code.")
public static long deadlineTimespecToDelayNanos(Time.timespec deadlineTimespec) {
    timespec currentTimespec = StackValue.get(SizeOf.get(timespec.class));
    getAbsoluteTimeNanos(currentTimespec);
    return TimeUtils.addOrMaxValue(deadlineTimespec.tv_nsec() - currentTimespec.tv_nsec(), TimeUtils.secondsToNanos((deadlineTimespec.tv_sec() - currentTimespec.tv_sec())));
}
Also used : Time.timespec(com.oracle.svm.core.posix.headers.Time.timespec) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 2 with Time.timespec

use of com.oracle.svm.core.posix.headers.Time.timespec in project graal by oracle.

the class PthreadConditionUtils method delayNanosToDeadlineTimespec.

/**
 * Turn a delay in nanoseconds into a deadline in a Time.timespec.
 */
@Uninterruptible(reason = "Called from uninterruptible code.")
public static void delayNanosToDeadlineTimespec(long delayNanos, Time.timespec result) {
    timespec currentTimespec = StackValue.get(SizeOf.get(timespec.class));
    getAbsoluteTimeNanos(currentTimespec);
    assert delayNanos >= 0;
    long sec = TimeUtils.addOrMaxValue(currentTimespec.tv_sec(), TimeUtils.divideNanosToSeconds(delayNanos));
    long nsec = currentTimespec.tv_nsec() + TimeUtils.remainderNanosToSeconds(delayNanos);
    if (nsec > TimeUtils.nanosPerSecond) {
        sec = TimeUtils.addOrMaxValue(sec, 1);
        nsec -= TimeUtils.nanosPerSecond;
    }
    assert nsec < TimeUtils.nanosPerSecond;
    result.set_tv_sec(sec);
    result.set_tv_nsec(nsec);
}
Also used : Time.timespec(com.oracle.svm.core.posix.headers.Time.timespec) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Aggregations

Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 Time.timespec (com.oracle.svm.core.posix.headers.Time.timespec)2