Skip to content

Improve Ractor-compliance #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/weakref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def initialize(orig)
when true, false, nil
@delegate_sd_obj = orig
else
@@__map[self] = orig
weakref_map[self] = orig
end
super
end

def __getobj__ # :nodoc:
@@__map[self] or defined?(@delegate_sd_obj) ? @delegate_sd_obj :
weakref_map[self] or defined?(@delegate_sd_obj) ? @delegate_sd_obj :
Kernel::raise(RefError, "Invalid Reference - probably recycled", Kernel::caller(2))
end

Expand All @@ -53,6 +53,18 @@ def __setobj__(obj) # :nodoc:
# Returns true if the referenced object is still alive.

def weakref_alive?
@@__map.key?(self) or defined?(@delegate_sd_obj)
weakref_map.key?(self) or defined?(@delegate_sd_obj)
end

def weakref_map
if defined?(::Object::Ractor)
if Ractor.current[:__WeakRef_map__].nil?
Ractor.current[:__WeakRef_map__] = ::ObjectSpace::WeakMap.new
end
Ractor.current[:__WeakRef_map__]
else
@@__map
end
end
private :weakref_map
end
Loading