Class ConditionVariable
In: lib/phusion_passenger/utils.rb
Parent: Object

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.

[Source]

     # File lib/phusion_passenger/utils.rb, line 882
882:         def timed_wait(mutex, secs)
883:                 ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
884:                 if secs > 100000000
885:                         # NOTE: If one calls timeout() on FreeBSD 5 with an
886:                         # argument of more than 100000000, then MRI will become
887:                         # stuck in an infite loop, blocking all threads. It seems
888:                         # that MRI uses select() to implement sleeping.
889:                         # I think that a value of more than 100000000 overflows
890:                         # select()'s data structures, causing it to behave incorrectly.
891:                         # So we just make sure we can't sleep more than 100000000
892:                         # seconds.
893:                         secs = 100000000
894:                 end
895:                 if ruby_engine == "jruby"
896:                         if secs > 0
897:                                 return wait(mutex, secs)
898:                         else
899:                                 return wait(mutex)
900:                         end
901:                 elsif RUBY_VERSION >= '1.9.2'
902:                         if secs > 0
903:                                 t1 = Time.now
904:                                 wait(mutex, secs)
905:                                 t2 = Time.now
906:                                 return t2.to_f - t1.to_f < secs
907:                         else
908:                                 wait(mutex)
909:                                 return true
910:                         end
911:                 else
912:                         if secs > 0
913:                                 Timeout.timeout(secs) do
914:                                         wait(mutex)
915:                                 end
916:                         else
917:                                 wait(mutex)
918:                         end
919:                         return true
920:                 end
921:         rescue Timeout::Error
922:                 return false
923:         end

This is like ConditionVariable.wait(), but allows one to wait a maximum amount of time. Raises Timeout::Error if the timeout has elapsed.

[Source]

     # File lib/phusion_passenger/utils.rb, line 927
927:         def timed_wait!(mutex, secs)
928:                 ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
929:                 if secs > 100000000
930:                         # See the corresponding note for timed_wait().
931:                         secs = 100000000
932:                 end
933:                 if ruby_engine == "jruby"
934:                         if secs > 0
935:                                 if !wait(mutex, secs)
936:                                         raise Timeout::Error, "Timeout"
937:                                 end
938:                         else
939:                                 wait(mutex)
940:                         end
941:                 elsif RUBY_VERSION >= '1.9.2'
942:                         if secs > 0
943:                                 t1 = Time.now
944:                                 wait(mutex, secs)
945:                                 t2 = Time.now
946:                                 if t2.to_f - t1.to_f >= secs
947:                                         raise Timeout::Error, "Timeout"
948:                                 end
949:                         else
950:                                 wait(mutex)
951:                         end
952:                 else
953:                         if secs > 0
954:                                 Timeout.timeout(secs) do
955:                                         wait(mutex)
956:                                 end
957:                         else
958:                                 wait(mutex)
959:                         end
960:                 end
961:                 return nil
962:         end

[Validate]