Sha256: 11ab0e0cfb4a4099dcf32f4a3f79f8150de95562099257b94b168e889ef806b9

Contents?: true

Size: 1.88 KB

Versions: 117

Compression:

Stored size: 1.88 KB

Contents

require 'concurrent/utility/engine'

module Concurrent

  module Utility

    # @!visibility private
    module NativeExtensionLoader

      def allow_c_extensions?
        Concurrent.on_cruby?
      end

      def c_extensions_loaded?
        defined?(@c_extensions_loaded) && @c_extensions_loaded
      end

      def java_extensions_loaded?
        defined?(@java_extensions_loaded) && @java_extensions_loaded
      end

      def load_native_extensions
        unless defined? Synchronization::AbstractObject
          raise 'native_extension_loader loaded before Synchronization::AbstractObject'
        end

        if Concurrent.on_cruby? && !c_extensions_loaded?
          ['concurrent/concurrent_ruby_ext',
           "concurrent/#{RUBY_VERSION[0..2]}/concurrent_ruby_ext"
          ].each { |p| try_load_c_extension p }
        end

        if Concurrent.on_jruby? && !java_extensions_loaded?
          begin
            require 'concurrent/concurrent_ruby.jar'
            set_java_extensions_loaded
          rescue LoadError => e
            raise e, "Java extensions are required for JRuby.\n" + e.message, e.backtrace
          end
        end
      end

      private

      def load_error_path(error)
        if error.respond_to? :path
          error.path
        else
          error.message.split(' -- ').last
        end
      end

      def set_c_extensions_loaded
        @c_extensions_loaded = true
      end

      def set_java_extensions_loaded
        @java_extensions_loaded = true
      end

      def try_load_c_extension(path)
        require path
        set_c_extensions_loaded
      rescue LoadError => e
        if load_error_path(e) == path
          # move on with pure-Ruby implementations
          # TODO (pitr-ch 12-Jul-2018): warning on verbose?
        else
          raise e
        end
      end

    end
  end

  # @!visibility private
  extend Utility::NativeExtensionLoader
end

Version data entries

117 entries across 103 versions & 25 rubygems

Version Path
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
concurrent-ruby-1.1.6 lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb
concurrent-ruby-1.1.6.pre1 lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/native_extension_loader.rb