This is like ConditionVariable.wait(), but allows one to wait a maximum amount of time. Returns true if this condition was signaled, false if a timeout occurred.
# File lib/phusion_passenger/utils.rb, line 525 525: def timed_wait(mutex, secs) 526: if secs > 100000000 527: # NOTE: If one calls timeout() on FreeBSD 5 with an 528: # argument of more than 100000000, then MRI will become 529: # stuck in an infite loop, blocking all threads. It seems 530: # that MRI uses select() to implement sleeping. 531: # I think that a value of more than 100000000 overflows 532: # select()'s data structures, causing it to behave incorrectly. 533: # So we just make sure we can't sleep more than 100000000 534: # seconds. 535: secs = 100000000 536: end 537: if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 538: if secs > 0 539: return wait(mutex, secs) 540: else 541: return wait(mutex) 542: end 543: else 544: require 'timeout' unless defined?(Timeout) 545: if secs > 0 546: Timeout.timeout(secs) do 547: wait(mutex) 548: end 549: else 550: wait(mutex) 551: end 552: return true 553: end 554: rescue Timeout::Error 555: return false 556: end
This is like ConditionVariable.wait(), but allows one to wait a maximum amount of time. Raises Timeout::Error if the timeout has elapsed.
# File lib/phusion_passenger/utils.rb, line 560 560: def timed_wait!(mutex, secs) 561: require 'timeout' unless defined?(Timeout) 562: if secs > 100000000 563: # See the corresponding note for timed_wait(). 564: secs = 100000000 565: end 566: if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 567: if secs > 0 568: if !wait(mutex, secs) 569: raise Timeout::Error, "Timeout" 570: end 571: else 572: wait(mutex) 573: end 574: else 575: if secs > 0 576: Timeout.timeout(secs) do 577: wait(mutex) 578: end 579: else 580: wait(mutex) 581: end 582: end 583: return nil 584: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.