File tree Expand file tree Collapse file tree 1 file changed +20
-22
lines changed Expand file tree Collapse file tree 1 file changed +20
-22
lines changed Original file line number Diff line number Diff line change @@ -11,33 +11,31 @@ def monotonic_time
11
11
else
12
12
13
13
require 'thread'
14
- class << self
15
14
16
- # @!visibility private
17
- @@global_monotonic_clock = Class . new {
18
- def initialize
19
- @mutex = Mutex . new
20
- @correction = 0
21
- @last_time = Time . now . to_f
22
- end
23
- def get_time
24
- @mutex . synchronize do
25
- @correction ||= 0 # compensating any back time shifts
26
- now = Time . now . to_f
27
- corrected_now = now + @correction
28
- if @last_time < corrected_now
29
- return @last_time = corrected_now
30
- else
31
- @correction += @last_time - corrected_now + 0.000_001
32
- return @last_time = @correction + now
33
- end
15
+ # @!visibility private
16
+ GLOBAL_MONOTONIC_CLOCK = Class . new {
17
+ def initialize
18
+ @mutex = Mutex . new
19
+ @correction = 0
20
+ @last_time = Time . now . to_f
21
+ end
22
+ def get_time
23
+ @mutex . synchronize do
24
+ @correction ||= 0 # compensating any back time shifts
25
+ now = Time . now . to_f
26
+ corrected_now = now + @correction
27
+ if @last_time < corrected_now
28
+ return @last_time = corrected_now
29
+ else
30
+ @correction += @last_time - corrected_now + 0.000_001
31
+ return @last_time = @correction + now
34
32
end
35
33
end
36
- } . new
37
- end
34
+ end
35
+ } . new
38
36
39
37
def monotonic_time
40
- @@global_monotonic_clock . get_time
38
+ GLOBAL_MONOTONIC_CLOCK . get_time
41
39
end
42
40
end
43
41
You can’t perform that action at this time.
0 commit comments