uringmachine 0.6 → 0.6.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: dc849d9467e24fa296a104e5b1caf71907495a3ed9cc68370bc6eb134a474cbf
4
- data.tar.gz: 4fcdf5cd6055321f37375094aa11b56696c894d6a2c47ed9f756fb9a40d79753
3
+ metadata.gz: 602ceb6207baea6b38287928500c73df48258ca2f8cf843f02b45fa65c591e3e
4
+ data.tar.gz: 78b2bc7a274b03e2ae51510e213be0d23911c4db102ad4ab7eee435f915bb5c0
5
5
  SHA512:
6
- metadata.gz: 3d83d7419000bd434bac101d72c6850274a71dd0324bd1732043cbdb08ef659b683e1010dc31093fe7a77e37368698db56592685bf7fe8a2f76ee4cd70cee52f
7
- data.tar.gz: dcb79682bbdc20b99bd312aad22145642c4479009250f01f2e0c83f506026218d973b5c6e8b0aecff4e993acbe3998822bccbdf1de7c77a025b7560b5860ca77
6
+ metadata.gz: c0dcbb93493c9778cf4ac12769f88611364d4e190c9e9dfa666543643e3aa3b44fa01cc49cf1ea2a1ba4798c4893b75e8b47e5b1eeac23b48bc5a6d84046e458
7
+ data.tar.gz: 5b012fcc3e7fd1a6d4e68aae58b9d099f19d5a89670772cdfdd6ef4ac76ed9781f533fd576e2b19b02c7774ba31d3ce6ee06dc590e04ce07a62e3c7fb2394191
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2025-04-23 Version 0.6.1
2
+
3
+ - Improve `#snooze` to prevent op completion starvation
4
+
1
5
  # 2025-04-23 Version 0.6
2
6
 
3
7
  - Add `#periodically` for multishot timeout
data/ext/um/um.c CHANGED
@@ -175,8 +175,28 @@ inline VALUE process_runqueue_op(struct um *machine, struct um_op *op) {
175
175
  inline VALUE um_fiber_switch(struct um *machine) {
176
176
  while (true) {
177
177
  struct um_op *op = um_runqueue_shift(machine);
178
- if (op)
178
+ if (op) {
179
+ // in case of a snooze, we need to prevent a situation where completions
180
+ // are not processed because the runqueue is never empty. Theoretically,
181
+ // we can still have a situation where multiple fibers are all doing a
182
+ // snooze repeatedly, which can prevent completions from being processed.
183
+
184
+ // is the op a snooze op and is this the same fiber as the current one?
185
+ if (unlikely(op->kind == OP_SCHEDULE && op->fiber == rb_fiber_current())) {
186
+ // are there any pending ops (i.e. waiting for completion)?
187
+ if (machine->pending_count > 0) {
188
+ // if yes, process completions, get runqueue head, put original op
189
+ // back on runqueue.
190
+ um_wait_for_and_process_ready_cqes(machine);
191
+ struct um_op *op2 = um_runqueue_shift(machine);
192
+ if (likely(op2 && op2 != op)) {
193
+ um_runqueue_push(machine, op);
194
+ op = op2;
195
+ }
196
+ }
197
+ }
179
198
  return process_runqueue_op(machine, op);
199
+ }
180
200
 
181
201
  um_wait_for_and_process_ready_cqes(machine);
182
202
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '0.6'
4
+ VERSION = '0.6.1'
5
5
  end
data/test/run.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob("#{__dir__}/test_*.rb").each do |path|
4
+ require(path)
5
+ end
data/test/test_um.rb CHANGED
@@ -917,32 +917,28 @@ class QueueTest < UMBaseTest
917
917
  q = UM::Queue.new
918
918
  buf = []
919
919
 
920
- f1 = Fiber.new do
920
+ machine.spin do
921
921
  buf << [1, machine.pop(q)]
922
- machine.yield
923
922
  end
924
923
 
925
- machine.schedule(f1, nil)
926
-
927
- f2 = Fiber.new do
924
+ machine.spin do
928
925
  buf << [2, machine.pop(q)]
929
- machine.yield
930
926
  end
931
927
 
932
- machine.schedule(f2, nil)
933
-
934
928
  machine.snooze
935
929
  assert_equal [], buf
930
+ assert_equal 2, machine.pending_count
936
931
 
937
932
  machine.push(q, :foo)
938
933
  assert_equal 1, q.count
939
- machine.sleep(0.02)
934
+ machine.snooze
935
+ assert_equal 1, machine.pending_count
940
936
  assert_equal [[1, :foo]], buf
941
937
 
942
938
  machine.push(q, :bar)
943
939
  assert_equal 1, q.count
944
940
 
945
- machine.sleep(0.02)
941
+ machine.snooze
946
942
  assert_equal [[1, :foo], [2, :bar]], buf
947
943
  assert_equal 0, q.count
948
944
  end
@@ -969,7 +965,7 @@ class QueueTest < UMBaseTest
969
965
  end
970
966
  machine.schedule(f2, nil)
971
967
 
972
- 3.times { machine.snooze }
968
+ machine.snooze
973
969
 
974
970
  assert_equal [[1, :bar], [2, :foo]], buf.sort
975
971
  assert_equal 0, q.count
@@ -996,12 +992,12 @@ class QueueTest < UMBaseTest
996
992
  end
997
993
  machine.schedule(f2, nil)
998
994
 
999
- machine.sleep 0.01
995
+ machine.snooze
1000
996
 
1001
997
  assert_equal [[1, :foo]], buf
1002
998
  machine.push(q, :bar)
1003
999
 
1004
- machine.sleep 0.01
1000
+ machine.snooze
1005
1001
  assert_equal [[1, :foo], [2, :bar]], buf
1006
1002
  end
1007
1003
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uringmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
@@ -136,6 +136,7 @@ files:
136
136
  - lib/uringmachine/version.rb
137
137
  - supressions/ruby.supp
138
138
  - test/helper.rb
139
+ - test/run.rb
139
140
  - test/test_actor.rb
140
141
  - test/test_async_op.rb
141
142
  - test/test_ssl.rb