Skip to content

Commit 6ca4c14

Browse files
committed
Moved clock_time from w/i Condition to utilities.
1 parent e625ad9 commit 6ca4c14

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

lib/concurrent/atomic/condition.rb

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/utility/clock_time'
2+
13
module Concurrent
24

35
# Condition is a better implementation of standard Ruby ConditionVariable. The
@@ -42,13 +44,13 @@ def initialize
4244
# @param [Object] timeout nil means no timeout
4345
# @return [Result]
4446
def wait(mutex, timeout = nil)
45-
start_time = clock_time
47+
start_time = Concurrent::clock_time
4648
@condition.wait(mutex, timeout)
4749

4850
if timeout.nil?
4951
Result.new(nil)
5052
else
51-
Result.new(start_time + timeout - clock_time)
53+
Result.new(start_time + timeout - Concurrent::clock_time)
5254
end
5355
end
5456

@@ -65,21 +67,5 @@ def broadcast
6567
@condition.broadcast
6668
true
6769
end
68-
69-
private
70-
71-
if defined?(Process::CLOCK_MONOTONIC)
72-
def clock_time
73-
Process.clock_gettime Process::CLOCK_MONOTONIC
74-
end
75-
elsif RUBY_PLATFORM == 'java'
76-
def clock_time
77-
java.lang.System.nanoTime() / 1_000_000_000.0
78-
end
79-
else
80-
def clock_time
81-
Time.now.to_f
82-
end
83-
end
8470
end
8571
end

lib/concurrent/utilities.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'concurrent/utility/clock_time'
12
require 'concurrent/utility/processor_count'
23
require 'concurrent/utility/timeout'
34
require 'concurrent/utility/timer'

lib/concurrent/utility/clock_time.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Concurrent
2+
3+
if defined?(Process::CLOCK_MONOTONIC)
4+
def clock_time
5+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
6+
end
7+
elsif RUBY_PLATFORM == 'java'
8+
def clock_time
9+
java.lang.System.nanoTime() / 1_000_000_000.0
10+
end
11+
else
12+
def clock_time
13+
Time.now.to_f
14+
end
15+
end
16+
17+
module_function :clock_time
18+
end

0 commit comments

Comments
 (0)