Sha256: ad22d6388c4a39cc341f468af196488286f87fe85a5beada4146006c3eb54b01

Contents?: true

Size: 1.41 KB

Versions: 89

Compression:

Stored size: 1.41 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 [attach] monotonic_get_time
  #
  #   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
  #
  #   @!macro monotonic_clock_warning
  def monotonic_time
    GLOBAL_MONOTONIC_CLOCK.get_time
  end

  module_function :monotonic_time
end

Version data entries

89 entries across 83 versions & 22 rubygems

Version Path
tdiary-5.0.2 vendor/bundle/gems/concurrent-ruby-1.0.2/lib/concurrent/utility/monotonic_time.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
tdiary-5.0.1 vendor/bundle/gems/concurrent-ruby-1.0.2/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.3.pre3-java lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.3.pre3 lib/concurrent/utility/monotonic_time.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/concurrent-ruby-1.0.2/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.2-java lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.2 lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.1-java lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.1 lib/concurrent/utility/monotonic_time.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/concurrent-ruby-1.0.0/lib/concurrent/utility/monotonic_time.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/concurrent-ruby-1.0.0/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.0-java lib/concurrent/utility/monotonic_time.rb