lib/gio2/loader.rb in gio2-3.4.9 vs lib/gio2/loader.rb in gio2-3.5.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2013-2019 Ruby-GNOME Project Team
+# Copyright (C) 2013-2021 Ruby-GNOME Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
@@ -37,10 +37,22 @@
end
end
end
require_extension
require_libraries
+
+ if defined?(Ractor)
+ [
+ @content_type_class,
+ @mime_type_class,
+ @dbus_module,
+ @resources_module,
+ ].each do |klass|
+ Ractor.make_shareable(klass::INVOKERS)
+ Ractor.make_shareable(klass.singleton_class::INVOKERS)
+ end
+ end
end
def require_extension
require "gio2.so"
end
@@ -53,22 +65,28 @@
require "gio2/file"
require "gio2/icon"
require "gio2/inet-address"
require "gio2/input-stream"
require "gio2/menu-item"
+ require "gio2/output-stream"
require "gio2/pollable-input-stream"
require "gio2/pollable-output-stream"
require "gio2/resources"
+ require "gio2/ruby-input-stream"
+ require "gio2/ruby-output-stream"
require "gio2/settings"
require "gio2/settings-schema-source"
require "gio2/simple-action"
require "gio2/deprecated"
end
def define_content_type_class
@content_type_class = Class.new do
+ const_set(:INVOKERS, {})
+ singleton_class.const_set(:INVOKERS, {})
+
def initialize(type)
@type = type
end
def to_s
@@ -78,10 +96,13 @@
@base_module.const_set("ContentType", @content_type_class)
end
def define_mime_type_class
@mime_type_class = Class.new do
+ const_set(:INVOKERS, {})
+ singleton_class.const_set(:INVOKERS, {})
+
def initialize(type)
@type = type
end
def to_s
@@ -90,16 +111,22 @@
end
@base_module.const_set("MimeType", @mime_type_class)
end
def define_dbus_module
- @dbus_module = Module.new
+ @dbus_module = Module.new do
+ const_set(:INVOKERS, {})
+ singleton_class.const_set(:INVOKERS, {})
+ end
@base_module.const_set("DBus", @dbus_module)
end
def define_resources_module
- @resources_module = Module.new
+ @resources_module = Module.new do
+ const_set(:INVOKERS, {})
+ singleton_class.const_set(:INVOKERS, {})
+ end
@base_module.const_set("Resources", @resources_module)
end
def load_function_info(info)
name = info.name
@@ -194,20 +221,63 @@
def error_parent_class(info)
Error
end
- def should_unlock_gvl?(function_info, klass)
+ def prepare_function_info_lock_gvl(function_info, klass)
+ super
case klass.name
+ when "Gio::Seekable"
+ function_info.lock_gvl_default = false
+ if defined?(Ractor)
+ predicate = Ractor.current.instance_eval do
+ lambda do |_, receiver|
+ receiver.is_a?(RubySeekable)
+ end
+ end
+ Ractor.make_shareable(predicate)
+ else
+ predicate = lambda do |_, receiver|
+ receiver.is_a?(RubySeekable)
+ end
+ end
+ function_info.add_lock_gvl_predicate(&predicate)
when "Gio::InputStream"
case function_info.name
- when "read", "read_all"
- true
- else
- false
+ when "read", "read_all", "skip", "close"
+ function_info.lock_gvl_default = false
+ if defined?(Ractor)
+ predicate = Ractor.current.instance_eval do
+ lambda do |_, receiver|
+ receiver.is_a?(RubyInputStream)
+ end
+ end
+ Ractor.make_shareable(predicate)
+ else
+ predicate = lambda do |_, receiver|
+ receiver.is_a?(RubyInputStream)
+ end
+ end
+ function_info.add_lock_gvl_predicate(&predicate)
end
- else
- false
+ when "Gio::OutputStream"
+ case function_info.name
+ when "write", "write_all", "flush", "close"
+ function_info.lock_gvl_default = false
+ if defined?(Ractor)
+ predicate = Ractor.current.instance_eval do
+ lambda do |_, receiver|
+ receiver.is_a?(RubyOutputStream)
+ end
+ end
+ Ractor.make_shareable(predicate)
+ else
+ predicate = lambda do |_, receiver|
+ receiver.is_a?(RubyOutputStream)
+ end
+ end
+ function_info.add_lock_gvl_predicate(&predicate)
+ end
end
end
end
end