File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ def wait(timeout = nil)
67
67
synchronize do
68
68
unless @set
69
69
iteration = @iteration
70
- ns_wait_until ( timeout ) { iteration != @iteration || @set }
70
+ ns_wait_until ( timeout ) { iteration < @iteration || @set }
71
71
else
72
72
true
73
73
end
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ def synchronize
28
28
raise NotImplementedError
29
29
end
30
30
31
+ private
32
+
31
33
# wait until another thread calls #signal or #broadcast,
32
34
# spurious wake-ups can happen.
33
35
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
@@ -54,16 +56,16 @@ def broadcast
54
56
synchronize { ns_broadcast }
55
57
end
56
58
57
- private
58
-
59
59
# @yield condition
60
60
def ns_wait_until ( timeout , &condition )
61
61
if timeout
62
62
wait_until = Concurrent . monotonic_time + timeout
63
63
while true
64
64
now = Concurrent . monotonic_time
65
65
condition_result = condition . call
66
- return condition_result if now >= wait_until || condition_result
66
+ # 0.001 correction to avoid error when `wait_until - now` is smaller than 0.0005 and rounded to 0
67
+ # when passed to java #wait(long timeout)
68
+ return condition_result if ( now + 0.001 ) >= wait_until || condition_result
67
69
ns_wait wait_until - now
68
70
end
69
71
else
@@ -123,7 +125,7 @@ def ns_signal
123
125
class RubySynchronizedObject < AbstractSynchronizedObject
124
126
def initialize
125
127
@__lock__do_not_use_directly = Mutex . new
126
- @__condition__do_not_use_directly = ConditionVariable . new
128
+ @__condition__do_not_use_directly = :: ConditionVariable . new
127
129
end
128
130
129
131
def synchronize
You can’t perform that action at this time.
0 commit comments