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 369 369: def timed_wait(mutex, secs) 370: if secs > 100000000 371: # NOTE: If one calls timeout() on FreeBSD 5 with an 372: # argument of more than 100000000, then MRI will become 373: # stuck in an infite loop, blocking all threads. It seems 374: # that MRI uses select() to implement sleeping. 375: # I think that a value of more than 100000000 overflows 376: # select()'s data structures, causing it to behave incorrectly. 377: # So we just make sure we can't sleep more than 100000000 378: # seconds. 379: secs = 100000000 380: end 381: if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 382: if secs > 0 383: return wait(mutex, secs) 384: else 385: return wait(mutex) 386: end 387: else 388: require 'timeout' unless defined?(Timeout) 389: if secs > 0 390: Timeout.timeout(secs) do 391: wait(mutex) 392: end 393: else 394: wait(mutex) 395: end 396: return true 397: end 398: rescue Timeout::Error 399: return false 400: 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 404 404: def timed_wait!(mutex, secs) 405: require 'timeout' unless defined?(Timeout) 406: if secs > 100000000 407: # See the corresponding note for timed_wait(). 408: secs = 100000000 409: end 410: if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 411: if secs > 0 412: if !wait(mutex, secs) 413: raise Timeout::Error, "Timeout" 414: end 415: else 416: wait(mutex) 417: end 418: else 419: if secs > 0 420: Timeout.timeout(secs) do 421: wait(mutex) 422: end 423: else 424: wait(mutex) 425: end 426: end 427: return nil 428: end