Skip to content

Commit 11b7622

Browse files
all clock_getres tests pass
1 parent 10daf35 commit 11b7622

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/main/ruby/core/process.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,32 @@ def self.time
117117

118118
def self.clock_getres(id, unit=:float_second)
119119
res = case id
120+
when :MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC,
121+
CLOCK_MONOTONIC
122+
1
120123
when :GETTIMEOFDAY_BASED_CLOCK_REALTIME,
121124
:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID,
122125
:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID
123126
1_000
127+
when CLOCK_REALTIME
128+
1_000_000
129+
when :TIMES_BASED_CLOCK_MONOTONIC,
130+
:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
131+
10_000_000
124132
when :TIME_BASED_CLOCK_REALTIME
125133
1_000_000_000
126-
when :MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC,
127-
:TIMES_BASED_CLOCK_MONOTONIC
128-
1
129-
when :TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID
134+
when Symbol
135+
raise Errno::EINVAL
130136
else
131-
res = Truffle::POSIX.truffleposix_clock_getres(id)
132-
Errno.handle if res == 0
137+
_res = Truffle::POSIX.truffleposix_clock_getres(id)
138+
if _res == 0 then
139+
Errno.handle
140+
else
141+
_res
142+
end
133143
end
134144

135-
if unit == :hertz then
145+
if :hertz == unit then
136146
1.0 / nanoseconds_to_unit(res,:float_second)
137147
else
138148
nanoseconds_to_unit(res,unit)
@@ -171,7 +181,7 @@ def self.normalize_clock_id(id)
171181
end
172182
end
173183

174-
def self.nanoseconds_to_unit(nanoseconds, unit = :nanosecond)
184+
def self.nanoseconds_to_unit(nanoseconds, unit)
175185
case unit
176186
when :nanosecond
177187
nanoseconds

0 commit comments

Comments
 (0)