@@ -120,11 +120,7 @@ def post_on(executor, *args, &job)
120120 class Event < Synchronization ::Object
121121 include Concern ::Deprecation
122122
123- class State < Synchronization ::Object
124- def initialize
125- ensure_ivar_visibility!
126- end
127-
123+ class State
128124 def completed?
129125 raise NotImplementedError
130126 end
@@ -331,19 +327,22 @@ def touched
331327 @Touched . value
332328 end
333329
330+ # only for debugging inspection
331+ def waiting_threads
332+ @Waiters . each . to_a
333+ end
334+
334335 private
335336
336337 def wait_until_complete ( timeout )
337- lock = Synchronization ::Lock . new
338-
339338 while true
340339 last_waiter = @Waiters . peek # waiters' state before completion
341340 break if completed?
342341
343342 # synchronize so it cannot be signaled before it waits
344343 synchronize do
345344 # ok only if completing thread did not start signaling
346- next unless @Waiters . compare_and_push last_waiter , lock
345+ next unless @Waiters . compare_and_push last_waiter , Thread . current
347346 ns_wait_until ( timeout ) { completed? }
348347 break
349348 end
@@ -407,7 +406,6 @@ def reason
407406 class Success < CompletedWithResult
408407 def initialize ( value )
409408 @Value = value
410- super ( )
411409 end
412410
413411 def success?
@@ -440,7 +438,6 @@ def apply(block)
440438 class Failed < CompletedWithResult
441439 def initialize ( reason )
442440 @Reason = reason
443- super ( )
444441 end
445442
446443 def success?
@@ -764,7 +761,6 @@ def hide_completable
764761 # @!visibility private
765762 class AbstractPromise < Synchronization ::Object
766763 def initialize ( future )
767- super ( &nil )
768764 @Future = future
769765 ensure_ivar_visibility!
770766 end
@@ -873,7 +869,7 @@ def initialize(future, blocked_by_futures, countdown, &block)
873869 @Countdown = AtomicFixnum . new countdown
874870
875871 super ( future )
876- blocked_by . each { |future | future . add_callback :pr_callback_notify_blocked , self }
872+ @BlockedBy . each { |future | future . add_callback :pr_callback_notify_blocked , self }
877873 end
878874
879875 # @api private
@@ -893,7 +889,7 @@ def touch
893889 blocked_by . each ( &:touch )
894890 end
895891
896- # @api private
892+ # !visibility private
897893 # for inspection only
898894 def blocked_by
899895 @BlockedBy
@@ -906,7 +902,7 @@ def inspect
906902 private
907903
908904 def initialize_blocked_by ( blocked_by_futures )
909- ( @BlockedBy = Array ( blocked_by_futures ) . freeze ) . size
905+ @BlockedBy = Array ( blocked_by_futures )
910906 end
911907
912908 def clear_blocked_by!
@@ -999,8 +995,6 @@ def on_completable(done_future)
999995 # @!visibility private
1000996 class ImmediatePromise < InnerPromise
1001997 def initialize ( default_executor , *args )
1002- # FIXME optimize, create completed futures directly, with/without args
1003-
1004998 super ( if args . empty?
1005999 Event . new ( self , default_executor ) . complete
10061000 else
@@ -1011,6 +1005,8 @@ def initialize(default_executor, *args)
10111005
10121006 # @!visibility private
10131007 class FlattingPromise < BlockedPromise
1008+
1009+ # !visibility private
10141010 def blocked_by
10151011 @BlockedBy . each . to_a
10161012 end
@@ -1044,7 +1040,6 @@ def initialize(blocked_by_future, levels, default_executor)
10441040
10451041 def initialize_blocked_by ( blocked_by_future )
10461042 @BlockedBy = LockFreeStack . new . push ( blocked_by_future )
1047- 1
10481043 end
10491044
10501045 def on_completable ( done_future )
0 commit comments