Sha256: 77082065c434e7ae19b08d12560c3ee34251bd7a02d24994fb85e8baaa7a8969

Contents?: true

Size: 1.35 KB

Versions: 110

Compression:

Stored size: 1.35 KB

Contents

require 'concurrent/synchronization'

module Concurrent

  class_definition = Class.new(Synchronization::LockableObject) do
    def initialize
      @last_time = Time.now.to_f
      super()
    end

    if defined?(Process::CLOCK_MONOTONIC)
      # @!visibility private
      def get_time
        Process.clock_gettime(Process::CLOCK_MONOTONIC)
      end
    elsif Concurrent.on_jruby?
      # @!visibility private
      def get_time
        java.lang.System.nanoTime() / 1_000_000_000.0
      end
    else

      # @!visibility private
      def get_time
        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

  # @!macro monotonic_get_time
  #
  #   Returns the current time a tracked by the application monotonic clock.
  #
  #   @return [Float] The current monotonic time since some unspecified
  #     starting point
  #
  #   @!macro monotonic_clock_warning
  def monotonic_time
    GLOBAL_MONOTONIC_CLOCK.get_time
  end

  module_function :monotonic_time
end

Version data entries

110 entries across 98 versions & 23 rubygems

Version Path
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.9 lib/concurrent-ruby/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.7/lib/concurrent-ruby/concurrent/utility/monotonic_time.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb