backports 3.20.0 → 3.20.1

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: b3d95602bc2a5f1d8835d424036e6d51671baa7c8d46f4482c61b6519044d493
4
- data.tar.gz: '059fa80520c54c368ad38f6477bbb2b9debe734970b0e007ba04be2b37c0138f'
3
+ metadata.gz: aa5429b607594bcd855bad1a66bbfdc01e3facb1f76be0c338fd549b502ec1c4
4
+ data.tar.gz: e7e08e840cc7559df5708a0bfa5d1499a3e809fb9bf79b260e4c98e7ca634c60
5
5
  SHA512:
6
- metadata.gz: 0b4031dc752ebb19df160368c272e37b0bf9a939288ccccc9d5043567efed030d157d2da1668ec0787216ab05f730b3ff8d7c23b78a5e2400719cd5183232a69
7
- data.tar.gz: c92bbe1f69c27f5ed6e18162e8fe96665a9828480bd2c10a13750f1b8190db53a0ef25b2009f2414cb3d193e22c0810b12a259ef84d079bac6f53dde9aafcd96
6
+ metadata.gz: 5e59f88a7ef8c1487cc1c1fb04d28a96d44b26d8cc5379a6ea9f18edfca62d97fe0b84c27a03c600a6137febf9096917f0ec1d7a52574fc536f7c345b2e256af
7
+ data.tar.gz: 9e732e7626034ae45dd1daf0cd54f20319854f27f041c5624e8c96d287a66ffeee780e8d0c142472e8b88cba597b65ee300b161b811acade9aaa697ff3352ff7
@@ -8,6 +8,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
8
8
 
9
9
  Note: [Next major version (X-mas 2021?)](https://github.com/marcandre/backports/issues/139) may drop support for Ruby < 2.2, please comment.
10
10
 
11
+ ## [3.20.1](https://github.com/marcandre/backports/compare/v3.20.0...v3.20.1) - 2021-01-03
12
+
13
+ ### Fixed
14
+
15
+ * Added `Ractor.[]` and `[]=` [#161]
16
+ * `Ractor.current` fixed from threads [#161]
17
+
11
18
  ## [3.20.0](https://github.com/marcandre/backports/compare/v3.19.0...v3.20.0) - 2020-12-30
12
19
 
13
20
  ### Added
@@ -8,6 +8,8 @@ class Ractor
8
8
  require_relative 'queues'
9
9
  require_relative 'sharing'
10
10
 
11
+ RactorThreadGroups = ::ObjectSpace::WeakMap.new # ThreadGroup => Ractor
12
+ private_constant :RactorThreadGroups
11
13
  # Implementation notes
12
14
  #
13
15
  # Uses one `Thread` for each `Ractor`, as well as queues for communication
@@ -37,7 +39,7 @@ class Ractor
37
39
  if Ractor.main == nil # then initializing main Ractor
38
40
  @ractor_thread = ::Thread.current
39
41
  @ractor_origin = nil
40
- @ractor_thread.thread_variable_set(:ractor, self)
42
+ @ractor_thread.thread_variable_set(:backports_ractor, self)
41
43
  else
42
44
  @ractor_origin = caller(1, 1).first.split(':in `').first
43
45
 
@@ -47,10 +49,12 @@ class Ractor
47
49
  end
48
50
 
49
51
  private def ractor_thread_start(args, block)
50
- Thread.new do
52
+ ::Thread.new do
51
53
  @ractor_thread = Thread.current
52
- @ractor_thread_group = ThreadGroup.new.add(@ractor_thread)
53
- ::Thread.current.thread_variable_set(:ractor, self)
54
+ @ractor_thread_group = ThreadGroup.new
55
+ RactorThreadGroups[@ractor_thread_group] = self
56
+ @ractor_thread_group.add(@ractor_thread)
57
+ ::Thread.current.thread_variable_set(:backports_ractor, self)
54
58
  result = nil
55
59
  begin
56
60
  result = instance_exec(*args, &block)
@@ -139,6 +143,19 @@ class Ractor
139
143
  ractor_incoming_queue.pop(&block)
140
144
  end
141
145
 
146
+ def [](key)
147
+ Ractor.current.ractor_locals[key]
148
+ end
149
+
150
+ def []=(key, value)
151
+ Ractor.current.ractor_locals[key] = value
152
+ end
153
+
154
+ # @api private
155
+ def ractor_locals
156
+ @ractor_locals ||= {}.compare_by_identity
157
+ end
158
+
142
159
  class << self
143
160
  def yield(value, move: false)
144
161
  value = ractor_isolate(value, move)
@@ -198,7 +215,8 @@ class Ractor
198
215
  end
199
216
 
200
217
  def current
201
- Thread.current.thread_variable_get(:ractor)
218
+ Thread.current.thread_variable_get(:backports_ractor) ||
219
+ Thread.current.thread_variable_set(:backports_ractor, ractor_find_current)
202
220
  end
203
221
 
204
222
  def count
@@ -222,6 +240,11 @@ class Ractor
222
240
  private def ractor_init
223
241
  @ractor_shareable = ::ObjectSpace::WeakMap.new
224
242
  @main = Ractor.new { nil }
243
+ RactorThreadGroups[::ThreadGroup::Default] = @main
244
+ end
245
+
246
+ private def ractor_find_current
247
+ RactorThreadGroups[Thread.current.group]
225
248
  end
226
249
  end
227
250
 
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.20.0" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.20.1" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.20.0
4
+ version: 3.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Essential backports that enable many of the nice features of Ruby for
14
14
  earlier versions.