atomic-ruby 0.4.0 → 0.5.0

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: 21542683125e7a193b4500ff05f3ee74249db2e3b16e71a3b10b46ff53a52d4b
4
- data.tar.gz: 609c1f8e8edb35ad1ad049a33c515a74522803b64a592ed49ac8666d8c06a8ba
3
+ metadata.gz: 10b5f273dd24628d2bf10a095cb875647bc922fc36697528c472053c61b2822c
4
+ data.tar.gz: b1b45d921decbc9bd2f927b8b6ed11a8de9e36ca1acacd4dde411953992ffb3a
5
5
  SHA512:
6
- metadata.gz: 8a3e15dee614e4455540272dba417192800fe85d41acdd0ff30babe8681f1d768b408a38fcf8acba878054fab96c94e085516299670b1643c591cc617a165919
7
- data.tar.gz: ae7b2e2e3a03019471d741a995d95a83f2e52eeb36137942b14cea55e8e76f8fd48ae734acbad5c2ac1a98a2fc8c88ddf5192ff6a2598f53555d7c08bfcbce9e
6
+ metadata.gz: c5ed7e71b51fa5b45e7031c7a08399f0158c588f3fe5b64844f7511fd959ebe7735fcc042d61b84c05729b961a133e7fa12a84663fe2e791b79fe3d02d6319f1
7
+ data.tar.gz: cd538c8c88fa9aa636ae0c0c69063b8288cde1af7b533c958c76096a7ecede7967ab45159ca04d010d507e084b8b13c38aa225d2ba675b146d2c7e8c473d147f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2025-07-17
4
+
5
+ - Add shortcut aliases for `AtomicRuby` namespaced classes
6
+
3
7
  ## [0.4.0] - 2025-07-06
4
8
 
5
9
  - Revert "Fix `AtomicThreadPool#<<` shutdown check race condition"
data/README.md CHANGED
@@ -21,12 +21,12 @@ gem install atomic-ruby
21
21
 
22
22
  ## Usage
23
23
 
24
- `AtomicRuby::Atom`:
24
+ `Atom`:
25
25
 
26
26
  ```ruby
27
27
  require "atomic-ruby"
28
28
 
29
- atom = AtomicRuby::Atom.new(0)
29
+ atom = Atom.new(0)
30
30
  p atom.value #=> 0
31
31
  atom.swap { |current_value| current_value + 1 }
32
32
  p atom.value #=> 1
@@ -34,12 +34,12 @@ atom.swap { |current_value| current_value + 1 }
34
34
  p atom.value #=> 2
35
35
  ```
36
36
 
37
- `AtomicRuby::AtomicBoolean`:
37
+ `AtomicBoolean`:
38
38
 
39
39
  ```ruby
40
40
  require "atomic-ruby"
41
41
 
42
- atom = AtomicRuby::AtomicBoolean.new(false)
42
+ atom = AtomicBoolean.new(false)
43
43
  p atom.value #=> false
44
44
  p atom.false? #=> true
45
45
  p atom.true? #=> false
@@ -49,14 +49,14 @@ atom.toggle
49
49
  p atom.false? #=> true
50
50
  ```
51
51
 
52
- `AtomicRuby::AtomicThreadPool`:
52
+ `AtomicThreadPool`:
53
53
 
54
54
  ```ruby
55
55
  require "atomic-ruby"
56
56
 
57
57
  results = []
58
58
 
59
- pool = AtomicRuby::AtomicThreadPool.new(size: 4)
59
+ pool = AtomicThreadPool.new(size: 4)
60
60
  p pool.length #=> 4
61
61
 
62
62
  10.times do |idx|
@@ -78,11 +78,30 @@ p results #=> [8, 7, 10, 9, 6, 5, 3, 4, 2, 1]
78
78
  p results.sort #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
79
79
  ```
80
80
 
81
+ `AtomicCountDownLatch`:
82
+
83
+ ```ruby
84
+ require "atomic-ruby"
85
+
86
+ latch = AtomicCountDownLatch.new(3)
87
+ p latch.count #=> 3
88
+
89
+ threads = 3.times.map do
90
+ Thread.new do
91
+ sleep(rand(5))
92
+ latch.count_down
93
+ end
94
+ end
95
+
96
+ latch.wait
97
+ p latch.count #=> 0
98
+ ```
99
+
81
100
  ## Benchmarks
82
101
 
83
102
  <details>
84
103
 
85
- <summary>AtomicRuby::Atom</summary>
104
+ <summary>Atom</summary>
86
105
 
87
106
  <br>
88
107
 
@@ -128,7 +147,7 @@ end
128
147
 
129
148
  class AtomicRubyAtomicBankAccount
130
149
  def initialize(balance)
131
- @balance = AtomicRuby::Atom.new(balance)
150
+ @balance = Atom.new(balance)
132
151
  end
133
152
 
134
153
  def balance
@@ -207,7 +226,7 @@ Atomic Ruby Atomic Bank Account: 5.107739 seconds
207
226
 
208
227
  <details>
209
228
 
210
- <summary>AtomicRuby::AtomicBoolean</summary>
229
+ <summary>AtomicBoolean</summary>
211
230
 
212
231
  ```ruby
213
232
  # frozen_string_literal: true
@@ -262,7 +281,7 @@ Benchmark.ips do |x|
262
281
  end
263
282
 
264
283
  x.report("Atomic Ruby Atomic Boolean Toggle") do
265
- boolean = AtomicRuby::AtomicBoolean.new(false)
284
+ boolean = AtomicBoolean.new(false)
266
285
  20.times.map do
267
286
  Thread.new do
268
287
  100.times do
@@ -308,7 +327,7 @@ Concurrent Ruby Atomic Boolean Toggle: 981.5 i/s - 1.30x slower
308
327
 
309
328
  <details>
310
329
 
311
- <summary>AtomicRuby::AtomicThreadPool</summary>
330
+ <summary>AtomicThreadPool</summary>
312
331
 
313
332
  <br>
314
333
 
@@ -325,7 +344,7 @@ results = []
325
344
  result = Benchmark.measure do
326
345
  pool = case idx
327
346
  when 0 then Concurrent::FixedThreadPool.new(20)
328
- when 1 then AtomicRuby::AtomicThreadPool.new(size: 20)
347
+ when 1 then AtomicThreadPool.new(size: 20)
329
348
  end
330
349
 
331
350
  100.times do
@@ -24,7 +24,7 @@ static void atomic_ruby_atom_compact(void *ptr) {
24
24
  }
25
25
 
26
26
  static const rb_data_type_t atomic_ruby_atom_type = {
27
- .wrap_struct_name = "AtomicRuby::Atom",
27
+ .wrap_struct_name = "Atom",
28
28
  .function = {
29
29
  .dmark = atomic_ruby_atom_mark,
30
30
  .dfree = atomic_ruby_atom_free,
Binary file
@@ -51,7 +51,7 @@ module AtomicRuby
51
51
  def start
52
52
  @threads = @size.times.map do |num|
53
53
  Thread.new(num) do |idx|
54
- thread_name = String.new("AtomicRuby::AtomicThreadPool thread #{idx}")
54
+ thread_name = String.new("AtomicThreadPool thread #{idx}")
55
55
  thread_name << " for #{@name}" if @name
56
56
  Thread.current.name = thread_name
57
57
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtomicRuby
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/atomic-ruby.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "atomic-ruby/atomic_boolean"
7
7
  require_relative "atomic-ruby/atomic_thread_pool"
8
8
  require_relative "atomic-ruby/atomic_count_down_latch"
9
9
 
10
- module AtomicRuby
11
- class Error < StandardError; end
12
- end
10
+ Atom = AtomicRuby::Atom
11
+ AtomicBoolean = AtomicRuby::AtomicBoolean
12
+ AtomicThreadPool = AtomicRuby::AtomicThreadPool
13
+ AtomicCountDownLatch = AtomicRuby::AtomicCountDownLatch
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.7.0.dev
54
+ rubygems_version: 3.6.9
55
55
  specification_version: 4
56
56
  summary: Atomic primitives for Ruby
57
57
  test_files: []