diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-06-11 12:48:34 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-08-03 09:30:00 +0900 |
commit | 97f3ceeaa5c66ad6a6a5f3f37339c4b1cbe71677 (patch) | |
tree | 74cac7d79d12333589a7e4220c69da3ff403ef29 /lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb | |
parent | 2b7e39f364d76c74af6e04aa3d96888a6aeef1cd (diff) |
[bundler/bundler] Bump net-http-persistent to 3.0.1
* Adds an extra artifice task to vendorize new `connection_pool`
dependency.
* Cherry-pick's needed Windows fix not yet merged into master branch of
`net-http-persistent`.
* Update bundler usages to be compatible with the new version, and fix
unit specs.
https://github.com/bundler/bundler/commit/0575baa6bb
Diffstat (limited to 'lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb')
-rw-r--r-- | lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb new file mode 100644 index 0000000000..5a9c4a27bb --- /dev/null +++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb @@ -0,0 +1,66 @@ +# Global monotonic clock from Concurrent Ruby 1.0. +# Copyright (c) Jerry D'Antonio -- released under the MIT license. +# Slightly modified; used with permission. +# https://github.com/ruby-concurrency/concurrent-ruby + +require 'thread' + +class Bundler::ConnectionPool + + class_definition = Class.new do + + if defined?(Process::CLOCK_MONOTONIC) + + # @!visibility private + def get_time + Process.clock_gettime(Process::CLOCK_MONOTONIC) + end + + elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' + + # @!visibility private + def get_time + java.lang.System.nanoTime() / 1_000_000_000.0 + end + + else + + # @!visibility private + def initialize + @mutex = Mutex.new + @last_time = Time.now.to_f + end + + # @!visibility private + def get_time + @mutex.synchronize do + now = Time.now.to_f + if @last_time < now + @last_time = now + else # clock has moved back in time + @last_time += 0.000_001 + end + end + end + end + end + + ## + # Clock that cannot be set and represents monotonic time since + # some unspecified starting point. + # + # @!visibility private + GLOBAL_MONOTONIC_CLOCK = class_definition.new + private_constant :GLOBAL_MONOTONIC_CLOCK + + class << self + ## + # Returns the current time a tracked by the application monotonic clock. + # + # @return [Float] The current monotonic time when `since` not given else + # the elapsed monotonic time between `since` and the current time + def monotonic_time + GLOBAL_MONOTONIC_CLOCK.get_time + end + end +end |