@@ -33,27 +33,34 @@ def synchronize
33
33
# wait until another thread calls #signal or #broadcast,
34
34
# spurious wake-ups can happen.
35
35
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
36
+ # @return [self]
36
37
def wait ( timeout = nil )
37
38
synchronize { ns_wait ( timeout ) }
39
+ self
38
40
end
39
41
40
42
# Wait until condition is met or timeout passes,
41
43
# protects against spurious wake-ups.
42
44
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
43
45
# @yield condition to be met
44
46
# @yieldreturn [true, false]
47
+ # @return [true, false]
45
48
def wait_until ( timeout = nil , &condition )
46
49
synchronize { ns_wait_until ( timeout , &condition ) }
47
50
end
48
51
49
52
# signal one waiting thread
53
+ # @return [self]
50
54
def signal
51
55
synchronize { ns_signal }
56
+ self
52
57
end
53
58
54
59
# broadcast to all waiting threads
60
+ # @return [self]
55
61
def broadcast
56
62
synchronize { ns_broadcast }
63
+ self
57
64
end
58
65
59
66
# @yield condition
@@ -74,21 +81,24 @@ def ns_wait_until(timeout, &condition)
74
81
end
75
82
end
76
83
84
+ # @return [self]
77
85
def ns_wait ( timeout )
78
86
raise NotImplementedError
79
87
end
80
88
89
+ # @return [self]
81
90
def ns_signal
82
91
raise NotImplementedError
83
92
end
84
93
94
+ # @return [self]
85
95
def ns_broadcast
86
96
raise NotImplementedError
87
97
end
88
98
89
99
end
90
100
91
- begin
101
+ if Concurrent . on_jruby?
92
102
require 'jruby'
93
103
94
104
# roughly more than 2x faster
@@ -108,18 +118,19 @@ def ns_wait(timeout)
108
118
else
109
119
JRuby . reference0 ( self ) . wait
110
120
end
121
+ self
111
122
end
112
123
113
124
def ns_broadcast
114
125
JRuby . reference0 ( self ) . notifyAll
126
+ self
115
127
end
116
128
117
129
def ns_signal
118
130
JRuby . reference0 ( self ) . notify
131
+ self
119
132
end
120
133
end
121
- rescue LoadError
122
- # ignore
123
134
end
124
135
125
136
class MutexSynchronizedObject < AbstractSynchronizedObject
@@ -140,14 +151,17 @@ def synchronize
140
151
141
152
def ns_signal
142
153
@__condition__do_not_use_directly . signal
154
+ self
143
155
end
144
156
145
157
def ns_broadcast
146
158
@__condition__do_not_use_directly . broadcast
159
+ self
147
160
end
148
161
149
162
def ns_wait ( timeout )
150
163
@__condition__do_not_use_directly . wait @__lock__do_not_use_directly , timeout
164
+ self
151
165
end
152
166
end
153
167
0 commit comments