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.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
tdiary-5.0.5 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/concurrent-ruby-1.0.0-java/lib/concurrent/utility/monotonic_time.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.2.1 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.2.0 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.9 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.8 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.7 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.6 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.4 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
tdiary-5.0.4 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.3 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.2 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.1 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
lazy_record-0.1.0 vendor/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.5-java lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.0.5 lib/concurrent/utility/monotonic_time.rb