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
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/monotonic_time.rb
tdiary-5.0.11 vendor/bundle/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/monotonic_time.rb
nullifyable-0.1.0 vendor/bundle/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.4 lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.3/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.3 lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.2 lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.1 lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.0.pre2 lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.0.pre1 lib/concurrent/utility/monotonic_time.rb