Methods
Public Instance methods
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.
[ show source ]
# File lib/phusion_passenger/utils.rb, line 446 446: def timed_wait(mutex, secs) 447: if secs > 100000000 448: # NOTE: If one calls timeout() on FreeBSD 5 with an 449: # argument of more than 100000000, then MRI will become 450: # stuck in an infite loop, blocking all threads. It seems 451: # that MRI uses select() to implement sleeping. 452: # I think that a value of more than 100000000 overflows 453: # select()'s data structures, causing it to behave incorrectly. 454: # So we just make sure we can't sleep more than 100000000 455: # seconds. 456: secs = 100000000 457: end 458: if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 459: if secs > 0 460: return wait(mutex, secs) 461: else 462: return wait(mutex) 463: end 464: else 465: require 'timeout' unless defined?(Timeout) 466: if secs > 0 467: Timeout.timeout(secs) do 468: wait(mutex) 469: end 470: else 471: wait(mutex) 472: end 473: return true 474: end 475: rescue Timeout::Error 476: return false 477: end
This is like ConditionVariable.wait(), but allows one to wait a maximum amount of time. Raises Timeout::Error if the timeout has elapsed.
[ show source ]
# File lib/phusion_passenger/utils.rb, line 481 481: def timed_wait!(mutex, secs) 482: require 'timeout' unless defined?(Timeout) 483: if secs > 100000000 484: # See the corresponding note for timed_wait(). 485: secs = 100000000 486: end 487: if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 488: if secs > 0 489: if !wait(mutex, secs) 490: raise Timeout::Error, "Timeout" 491: end 492: else 493: wait(mutex) 494: end 495: else 496: if secs > 0 497: Timeout.timeout(secs) do 498: wait(mutex) 499: end 500: else 501: wait(mutex) 502: end 503: end 504: return nil 505: end