@@ -179,21 +179,66 @@ def synchronize
179
179
180
180
def ns_wait ( timeout )
181
181
@__condition__do_not_use_directly . wait timeout
182
+ self
183
+ end
184
+ end
185
+
186
+ if Concurrent . on_rbx?
187
+ class RbxSynchronizedObject < AbstractSynchronizedObject
188
+ def initialize
189
+ @waiters = [ ]
190
+ end
191
+
192
+ def synchronize ( &block )
193
+ Rubinius . synchronize ( self , &block )
194
+ end
195
+
196
+ private
197
+
198
+ def ns_wait ( timeout = nil )
199
+ wchan = Rubinius ::Channel . new
200
+
201
+ begin
202
+ @waiters . push wchan
203
+ Rubinius . unlock ( self )
204
+ signaled = wchan . receive_timeout timeout
205
+ ensure
206
+ Rubinius . lock ( self )
207
+
208
+ if !signaled && !@waiters . delete ( wchan )
209
+ # we timed out, but got signaled afterwards,
210
+ # so pass that signal on to the next waiter
211
+ @waiters . shift << true unless @waiters . empty?
212
+ end
213
+ end
214
+
215
+ self
216
+ end
217
+
218
+ def ns_signal
219
+ @waiters . shift << true unless @waiters . empty?
220
+ self
221
+ end
222
+
223
+ def ns_broadcast
224
+ @waiters . shift << true until @waiters . empty?
225
+ self
226
+ end
182
227
end
183
228
end
184
229
185
230
# TODO add rbx implementation
186
- SynchronizedObject = Class . new case
187
- when Concurrent . on_jruby?
188
- JavaSynchronizedObject
189
- when Concurrent . on_cruby? && ( RUBY_VERSION . split ( '.' ) . map ( &:to_i ) <=> [ 1 , 9 , 3 ] ) >= 0
190
- MonitorSynchronizedObject
191
- when Concurrent . on_cruby?
192
- MutexSynchronizedObject
193
- when Concurrent . on_rbx?
194
- # TODO better implementation
195
- MonitorSynchronizedObject
196
- else
197
- MutexSynchronizedObject
198
- end
231
+ class SynchronizedObject < case
232
+ when Concurrent . on_jruby?
233
+ JavaSynchronizedObject
234
+ when Concurrent . on_cruby? && ( RUBY_VERSION . split ( '.' ) . map ( &:to_i ) <=> [ 1 , 9 , 3 ] ) >= 0
235
+ MonitorSynchronizedObject
236
+ when Concurrent . on_cruby?
237
+ MutexSynchronizedObject
238
+ when Concurrent . on_rbx?
239
+ RbxSynchronizedObject
240
+ else
241
+ MutexSynchronizedObject
242
+ end
243
+ end
199
244
end
0 commit comments