Skip to content

Commit c5eab83

Browse files
committed
Fallback monotonic clock is now a Synchronization::Object.
1 parent 504b114 commit c5eab83

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/concurrent/utility/monotonic_time.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
require 'concurrent/synchronization'
2+
13
module Concurrent
24

35
# Clock that cannot be set and represents monotonic time since
46
# some unspecified starting point.
57
# @!visibility private
6-
GLOBAL_MONOTONIC_CLOCK = Class.new {
8+
GLOBAL_MONOTONIC_CLOCK = Class.new(Synchronization::Object) {
79

810
if defined?(Process::CLOCK_MONOTONIC)
911
# @!visibility private
@@ -17,17 +19,9 @@ def get_time
1719
end
1820
else
1921

20-
require 'thread'
21-
22-
# @!visibility private
23-
def initialize
24-
@mutex = Mutex.new
25-
@last_time = Time.now.to_f
26-
end
27-
2822
# @!visibility private
2923
def get_time
30-
@mutex.synchronize do
24+
synchronize do
3125
now = Time.now.to_f
3226
if @last_time < now
3327
@last_time = now
@@ -36,6 +30,13 @@ def get_time
3630
end
3731
end
3832
end
33+
34+
protected
35+
36+
# @!visibility private
37+
def ns_initialize
38+
@last_time = Time.now.to_f
39+
end
3940
end
4041
}.new
4142
private_constant :GLOBAL_MONOTONIC_CLOCK

0 commit comments

Comments
 (0)