ractorize 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7827fd6bd911724e81479f2966f75aafb825c1320fb870531b08db1079b5b9c
|
|
4
|
+
data.tar.gz: bf7da9b30088e3554637b646ef4bb5ceab085d076f3e0097c68f236d647b3baf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7858c116a76c408a6c341ee8007a91a50e4caae089978564d2704535845248e14272c18909bd8f4e5458e6dbe97262afb2acc088fd79412f5231ff1f56d3de1
|
|
7
|
+
data.tar.gz: 0e3b0165b66489c83b3dc7ebe37873ad6600e4fb9239eeaa326440d700112bf13255a67532f84fdfd15c3d37afcb93285742a4a50e5eef0993231bab1c5976ff
|
data/CHANGELOG.md
CHANGED
|
@@ -2,11 +2,13 @@ module Ractorize
|
|
|
2
2
|
module GarbageCollection
|
|
3
3
|
class Tracker
|
|
4
4
|
attr_accessor :ractorized_object_id_to_ractor,
|
|
5
|
-
:thunk_id_to_ractor
|
|
5
|
+
:thunk_id_to_ractor,
|
|
6
|
+
:ractor_to_thunk_ids
|
|
6
7
|
|
|
7
8
|
def initialize
|
|
8
9
|
self.ractorized_object_id_to_ractor = ObjectSpace::WeakMap.new
|
|
9
10
|
self.thunk_id_to_ractor = ObjectSpace::WeakMap.new
|
|
11
|
+
self.ractor_to_thunk_ids = ObjectSpace::WeakKeyMap.new
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def track_ractorized_object(ractorized_object)
|
|
@@ -24,9 +26,32 @@ module Ractorize
|
|
|
24
26
|
thunk_id_to_ractor[thunk_id] = ractor
|
|
25
27
|
end
|
|
26
28
|
|
|
29
|
+
def thunk_cloned(old_thunk_id, new_thunk_id, thunk_ractor)
|
|
30
|
+
thunk_ids = ractor_to_thunk_ids[thunk_ractor]
|
|
31
|
+
|
|
32
|
+
if thunk_ids
|
|
33
|
+
thunk_ids << new_thunk_id
|
|
34
|
+
else
|
|
35
|
+
ractor_to_thunk_ids[thunk_ractor] = [old_thunk_id, new_thunk_id]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
thunk_id_to_ractor[new_thunk_id] = thunk_ractor
|
|
39
|
+
end
|
|
40
|
+
|
|
27
41
|
def cleanup_after_thunk(thunk_id)
|
|
28
42
|
ractor = thunk_id_to_ractor.delete(thunk_id)
|
|
29
|
-
|
|
43
|
+
|
|
44
|
+
return unless ractor
|
|
45
|
+
|
|
46
|
+
thunk_ids = ractor_to_thunk_ids[ractor]
|
|
47
|
+
|
|
48
|
+
if thunk_ids
|
|
49
|
+
thunk_ids.delete(thunk_id)
|
|
50
|
+
|
|
51
|
+
return unless thunk_ids.empty?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
ractor << :__close__
|
|
30
55
|
rescue Ractor::ClosedError
|
|
31
56
|
# do nothing
|
|
32
57
|
end
|
|
@@ -21,6 +21,8 @@ module Ractorize
|
|
|
21
21
|
tracker.cleanup_after_ractorized_object(ractorized_object_id)
|
|
22
22
|
in :track_thunk, thunk_id, thunk_ractor
|
|
23
23
|
tracker.track_thunk(thunk_id, thunk_ractor)
|
|
24
|
+
in :thunk_cloned, old_thunk_id, new_thunk_id, thunk_ractor
|
|
25
|
+
tracker.thunk_cloned(old_thunk_id, new_thunk_id, thunk_ractor)
|
|
24
26
|
in :cleanup_after_thunk, thunk_id
|
|
25
27
|
tracker.cleanup_after_thunk(thunk_id)
|
|
26
28
|
end
|
|
@@ -14,7 +14,7 @@ module Ractorize
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def track_thunk(thunk)
|
|
17
|
-
# We have to define the finalizer here, not in the tracker, because it's not
|
|
17
|
+
# We have to define the finalizer here, not in the tracker, because it's not shareable
|
|
18
18
|
ObjectSpace.define_finalizer(thunk, &finalize_thunk_proc)
|
|
19
19
|
|
|
20
20
|
begin
|
|
@@ -24,6 +24,24 @@ module Ractorize
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def thunk_cloned(old_thunk, new_thunk)
|
|
28
|
+
ractor = old_thunk.__thunk_ractor__
|
|
29
|
+
|
|
30
|
+
# We have to define the finalizer here, not in the tracker, because it's not shareable
|
|
31
|
+
# ObjectSpace.define_finalizer(new_thunk, &finalize_thunk_proc)
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
TRACKING_RACTOR << [
|
|
35
|
+
:thunk_cloned,
|
|
36
|
+
old_thunk.__object_id__,
|
|
37
|
+
new_thunk.__object_id__,
|
|
38
|
+
ractor
|
|
39
|
+
].freeze
|
|
40
|
+
rescue TrackingRactor::ClosedError
|
|
41
|
+
# do nothing
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
27
45
|
def cleanup_after_ractorized_object(ractorized_object_id)
|
|
28
46
|
TRACKING_RACTOR << [:cleanup_after_ractorized_object, ractorized_object_id].freeze
|
|
29
47
|
rescue Ractor::ClosedError
|
data/src/ractorize/thunk.rb
CHANGED
|
@@ -10,13 +10,20 @@ module Ractorize
|
|
|
10
10
|
::Ractorize::GarbageCollection.track_thunk(self)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def initialize_clone(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
def initialize_clone(original_thunk)
|
|
14
|
+
if __resolved__? && original_thunk.__resolved__?
|
|
15
|
+
# Seems this could happen if we had a frozen thunk whose @__value__ is not shareable
|
|
16
|
+
# Since the thunk's ractor is already gone nothing to worry about
|
|
17
|
+
return
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
self.__object_id__ = ::Object.instance_method(:object_id).bind_call(self)
|
|
21
|
+
|
|
22
|
+
::Ractorize::GarbageCollection.thunk_cloned(original_thunk, self)
|
|
18
23
|
end
|
|
19
24
|
|
|
25
|
+
def __resolved__? = defined?(@__value__)
|
|
26
|
+
|
|
20
27
|
def method_missing(...)
|
|
21
28
|
__value__.__send__(...)
|
|
22
29
|
end
|