polyphony 0.82 → 0.84.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 +4 -4
- data/.gitmodules +3 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +14 -0
- data/ext/polyphony/backend_common.c +15 -10
- data/ext/polyphony/backend_common.h +5 -4
- data/ext/polyphony/backend_io_uring.c +128 -157
- data/ext/polyphony/backend_libev.c +148 -159
- data/ext/polyphony/extconf.rb +20 -1
- data/ext/polyphony/io_extensions.c +440 -0
- data/ext/polyphony/pipe.c +109 -0
- data/ext/polyphony/polyphony.c +5 -0
- data/ext/polyphony/polyphony.h +6 -0
- data/ext/polyphony/polyphony_ext.c +7 -2
- data/ext/polyphony/zlib_conf.rb +119 -0
- data/lib/polyphony/extensions/io.rb +20 -2
- data/lib/polyphony/extensions/pipe.rb +171 -0
- data/lib/polyphony/extensions.rb +1 -0
- data/lib/polyphony/version.rb +1 -1
- data/lib/polyphony.rb +4 -0
- data/test/helper.rb +4 -0
- data/test/test_backend.rb +3 -48
- data/test/test_global_api.rb +23 -23
- data/test/test_io.rb +391 -0
- data/test/test_pipe.rb +41 -0
- data/test/test_process_supervision.rb +1 -1
- data/test/test_socket.rb +1 -0
- metadata +7 -13
- data/ext/liburing/liburing/README.md +0 -4
- data/ext/liburing/liburing/barrier.h +0 -73
- data/ext/liburing/liburing/compat.h +0 -15
- data/ext/liburing/liburing/io_uring.h +0 -343
- data/ext/liburing/liburing.h +0 -585
- data/ext/liburing/queue.c +0 -333
- data/ext/liburing/register.c +0 -187
- data/ext/liburing/setup.c +0 -210
- data/ext/liburing/syscall.c +0 -54
- data/ext/liburing/syscall.h +0 -18
- data/ext/polyphony/liburing.c +0 -8
data/test/test_io.rb
CHANGED
@@ -279,6 +279,153 @@ class IOTest < MiniTest::Test
|
|
279
279
|
sleep 0.01
|
280
280
|
assert_equal ['foo', 'bar', 'baz'], receiver.buffer
|
281
281
|
end
|
282
|
+
|
283
|
+
def test_splice_from
|
284
|
+
i1, o1 = IO.pipe
|
285
|
+
i2, o2 = IO.pipe
|
286
|
+
len = nil
|
287
|
+
|
288
|
+
spin {
|
289
|
+
len = o2.splice_from(i1, 1000)
|
290
|
+
o2.close
|
291
|
+
}
|
292
|
+
|
293
|
+
o1.write('foobar')
|
294
|
+
result = i2.read
|
295
|
+
|
296
|
+
assert_equal 'foobar', result
|
297
|
+
assert_equal 6, len
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_splice_class_method
|
301
|
+
i1, o1 = IO.pipe
|
302
|
+
i2, o2 = IO.pipe
|
303
|
+
len = nil
|
304
|
+
|
305
|
+
spin {
|
306
|
+
len = IO.splice(i1, o2, 1000)
|
307
|
+
o2.close
|
308
|
+
}
|
309
|
+
|
310
|
+
o1.write('foobar')
|
311
|
+
result = i2.read
|
312
|
+
|
313
|
+
assert_equal 'foobar', result
|
314
|
+
assert_equal 6, len
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_splice_to_eof_from
|
318
|
+
i1, o1 = IO.pipe
|
319
|
+
i2, o2 = IO.pipe
|
320
|
+
len = nil
|
321
|
+
|
322
|
+
f = spin {
|
323
|
+
len = o2.splice_to_eof_from(i1, 1000)
|
324
|
+
o2.close
|
325
|
+
}
|
326
|
+
|
327
|
+
o1.write('foo')
|
328
|
+
result = i2.readpartial(1000)
|
329
|
+
assert_equal 'foo', result
|
330
|
+
|
331
|
+
o1.write('bar')
|
332
|
+
result = i2.readpartial(1000)
|
333
|
+
assert_equal 'bar', result
|
334
|
+
o1.close
|
335
|
+
f.await
|
336
|
+
assert_equal 6, len
|
337
|
+
ensure
|
338
|
+
if f.alive?
|
339
|
+
f.interrupt
|
340
|
+
f.await
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_splice_to_eof_class_method
|
345
|
+
i1, o1 = IO.pipe
|
346
|
+
i2, o2 = IO.pipe
|
347
|
+
len = nil
|
348
|
+
|
349
|
+
f = spin {
|
350
|
+
len = IO.splice_to_eof(i1, o2, 1000)
|
351
|
+
o2.close
|
352
|
+
}
|
353
|
+
|
354
|
+
o1.write('foo')
|
355
|
+
result = i2.readpartial(1000)
|
356
|
+
assert_equal 'foo', result
|
357
|
+
|
358
|
+
o1.write('bar')
|
359
|
+
result = i2.readpartial(1000)
|
360
|
+
assert_equal 'bar', result
|
361
|
+
o1.close
|
362
|
+
f.await
|
363
|
+
assert_equal 6, len
|
364
|
+
ensure
|
365
|
+
if f.alive?
|
366
|
+
f.interrupt
|
367
|
+
f.await
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_tee_from
|
372
|
+
skip "tested only on Linux" unless RUBY_PLATFORM =~ /linux/
|
373
|
+
|
374
|
+
src = Polyphony.pipe
|
375
|
+
dest1 = Polyphony.pipe
|
376
|
+
dest2 = Polyphony.pipe
|
377
|
+
|
378
|
+
len1 = len2 = nil
|
379
|
+
|
380
|
+
spin {
|
381
|
+
len1 = dest1.tee_from(src, 1000)
|
382
|
+
dest1.close
|
383
|
+
len2 = IO.splice(src, dest2, 1000)
|
384
|
+
dest2.close
|
385
|
+
}
|
386
|
+
|
387
|
+
src << 'foobar'
|
388
|
+
src.close
|
389
|
+
result1 = dest1.read
|
390
|
+
result2 = dest2.read
|
391
|
+
|
392
|
+
assert_equal 'foobar', result1
|
393
|
+
assert_equal 6, len1
|
394
|
+
|
395
|
+
assert_equal 'foobar', result2
|
396
|
+
assert_equal 6, len2
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_tee_class_method
|
400
|
+
skip "tested only on Linux" unless RUBY_PLATFORM =~ /linux/
|
401
|
+
|
402
|
+
src = Polyphony.pipe
|
403
|
+
dest1 = Polyphony.pipe
|
404
|
+
dest2 = Polyphony.pipe
|
405
|
+
|
406
|
+
len1 = len2 = nil
|
407
|
+
|
408
|
+
spin {
|
409
|
+
len1 = IO.tee(src, dest1, 1000)
|
410
|
+
dest1.close
|
411
|
+
len2 = IO.splice(src, dest2, 1000)
|
412
|
+
dest2.close
|
413
|
+
}
|
414
|
+
|
415
|
+
src << 'foobar'
|
416
|
+
src.close
|
417
|
+
result1 = dest1.read
|
418
|
+
result2 = dest2.read
|
419
|
+
|
420
|
+
assert_equal 'foobar', result1
|
421
|
+
assert_equal 6, len1
|
422
|
+
|
423
|
+
assert_equal 'foobar', result2
|
424
|
+
assert_equal 6, len2
|
425
|
+
end
|
426
|
+
|
427
|
+
|
428
|
+
|
282
429
|
end
|
283
430
|
|
284
431
|
class IOWithRawBufferTest < MiniTest::Test
|
@@ -503,3 +650,247 @@ class IOClassMethodsTest < MiniTest::Test
|
|
503
650
|
assert_equal ['foo', 'bar'], buf
|
504
651
|
end
|
505
652
|
end
|
653
|
+
|
654
|
+
class IOExtensionsTest < MiniTest::Test
|
655
|
+
def test_deflate
|
656
|
+
i, o = IO.pipe
|
657
|
+
r, w = IO.pipe
|
658
|
+
|
659
|
+
spin {
|
660
|
+
IO.deflate(i, w)
|
661
|
+
w.close
|
662
|
+
}
|
663
|
+
|
664
|
+
o << 'foobar' * 20
|
665
|
+
o.close
|
666
|
+
|
667
|
+
data = r.read
|
668
|
+
msg = Zlib::Inflate.inflate(data)
|
669
|
+
assert_equal 'foobar' * 20, msg
|
670
|
+
end
|
671
|
+
|
672
|
+
def test_inflate
|
673
|
+
i, o = IO.pipe
|
674
|
+
r, w = IO.pipe
|
675
|
+
|
676
|
+
spin {
|
677
|
+
data = Zlib::Deflate.deflate('foobar', 9)
|
678
|
+
o << data
|
679
|
+
o.close
|
680
|
+
}
|
681
|
+
|
682
|
+
IO.inflate(i, w)
|
683
|
+
w.close
|
684
|
+
msg = r.read
|
685
|
+
assert_equal 'foobar', msg
|
686
|
+
end
|
687
|
+
|
688
|
+
def test_gzip
|
689
|
+
src = Polyphony.pipe
|
690
|
+
dest = Polyphony.pipe
|
691
|
+
now = nil
|
692
|
+
|
693
|
+
spin {
|
694
|
+
now = Time.now
|
695
|
+
IO.gzip(src, dest)
|
696
|
+
dest.close
|
697
|
+
}
|
698
|
+
|
699
|
+
src << IO.read(__FILE__)
|
700
|
+
src.close
|
701
|
+
|
702
|
+
gz = Zlib::GzipReader.new(dest)
|
703
|
+
data = gz.read
|
704
|
+
assert_equal IO.read(__FILE__), data
|
705
|
+
assert_in_range (now-2)..(now+1), gz.mtime
|
706
|
+
assert_nil gz.orig_name
|
707
|
+
assert_nil gz.comment
|
708
|
+
end
|
709
|
+
|
710
|
+
def test_gzip_with_mtime_int
|
711
|
+
src = Polyphony.pipe
|
712
|
+
dest = Polyphony.pipe
|
713
|
+
|
714
|
+
spin {
|
715
|
+
IO.gzip(src, dest, mtime: 42)
|
716
|
+
dest.close
|
717
|
+
}
|
718
|
+
|
719
|
+
src << IO.read(__FILE__)
|
720
|
+
src.close
|
721
|
+
|
722
|
+
gz = Zlib::GzipReader.new(dest)
|
723
|
+
data = gz.read
|
724
|
+
assert_equal IO.read(__FILE__), data
|
725
|
+
assert_equal Time.at(42), gz.mtime
|
726
|
+
end
|
727
|
+
|
728
|
+
def test_gzip_with_mtime_false
|
729
|
+
src = Polyphony.pipe
|
730
|
+
dest = Polyphony.pipe
|
731
|
+
|
732
|
+
spin {
|
733
|
+
IO.gzip(src, dest, mtime: false)
|
734
|
+
dest.close
|
735
|
+
}
|
736
|
+
|
737
|
+
src << IO.read(__FILE__)
|
738
|
+
src.close
|
739
|
+
|
740
|
+
gz = Zlib::GzipReader.new(dest)
|
741
|
+
data = gz.read
|
742
|
+
assert_equal IO.read(__FILE__), data
|
743
|
+
assert_equal Time.at(0), gz.mtime
|
744
|
+
end
|
745
|
+
|
746
|
+
def test_gzip_with_mtime_time
|
747
|
+
src = Polyphony.pipe
|
748
|
+
dest = Polyphony.pipe
|
749
|
+
t = Time.at(Time.now.to_i) - rand(300000)
|
750
|
+
|
751
|
+
spin {
|
752
|
+
IO.gzip(src, dest, mtime: t)
|
753
|
+
dest.close
|
754
|
+
}
|
755
|
+
|
756
|
+
src << IO.read(__FILE__)
|
757
|
+
src.close
|
758
|
+
|
759
|
+
gz = Zlib::GzipReader.new(dest)
|
760
|
+
data = gz.read
|
761
|
+
assert_equal IO.read(__FILE__), data
|
762
|
+
assert_equal t, gz.mtime
|
763
|
+
end
|
764
|
+
|
765
|
+
def test_gzip_with_orig_name
|
766
|
+
src = Polyphony.pipe
|
767
|
+
dest = Polyphony.pipe
|
768
|
+
|
769
|
+
spin {
|
770
|
+
IO.gzip(src, dest, orig_name: '/foo/bar')
|
771
|
+
dest.close
|
772
|
+
}
|
773
|
+
|
774
|
+
src << IO.read(__FILE__)
|
775
|
+
src.close
|
776
|
+
|
777
|
+
gz = Zlib::GzipReader.new(dest)
|
778
|
+
data = gz.read
|
779
|
+
assert_equal IO.read(__FILE__), data
|
780
|
+
assert_equal '/foo/bar', gz.orig_name
|
781
|
+
end
|
782
|
+
|
783
|
+
def test_gzip_with_comment
|
784
|
+
src = Polyphony.pipe
|
785
|
+
dest = Polyphony.pipe
|
786
|
+
|
787
|
+
spin {
|
788
|
+
IO.gzip(src, dest, comment: 'hello!')
|
789
|
+
dest.close
|
790
|
+
}
|
791
|
+
|
792
|
+
src << IO.read(__FILE__)
|
793
|
+
src.close
|
794
|
+
|
795
|
+
gz = Zlib::GzipReader.new(dest)
|
796
|
+
data = gz.read
|
797
|
+
assert_equal IO.read(__FILE__), data
|
798
|
+
assert_equal 'hello!', gz.comment
|
799
|
+
end
|
800
|
+
|
801
|
+
def test_gunzip
|
802
|
+
src = Polyphony.pipe
|
803
|
+
dest = Polyphony.pipe
|
804
|
+
|
805
|
+
spin {
|
806
|
+
IO.gunzip(src, dest)
|
807
|
+
dest.close
|
808
|
+
}
|
809
|
+
|
810
|
+
gz = Zlib::GzipWriter.new(src, 9)
|
811
|
+
gz << 'foobar'#IO.read(__FILE__)
|
812
|
+
gz.close
|
813
|
+
|
814
|
+
data = dest.read
|
815
|
+
# assert_equal IO.read(__FILE__), data
|
816
|
+
assert_equal 'foobar', data
|
817
|
+
end
|
818
|
+
|
819
|
+
def test_gunzip_multi
|
820
|
+
src1 = Polyphony.pipe
|
821
|
+
src2 = Polyphony.pipe
|
822
|
+
dest = Polyphony.pipe
|
823
|
+
|
824
|
+
spin {
|
825
|
+
IO.gunzip(src1, dest)
|
826
|
+
IO.gunzip(src2, dest)
|
827
|
+
dest.close
|
828
|
+
}
|
829
|
+
|
830
|
+
gz1 = Zlib::GzipWriter.new(src1)
|
831
|
+
gz1 << 'foobar'
|
832
|
+
gz1.close
|
833
|
+
|
834
|
+
gz1 = Zlib::GzipWriter.new(src2)
|
835
|
+
gz1 << 'raboof'
|
836
|
+
gz1.close
|
837
|
+
|
838
|
+
data = dest.read
|
839
|
+
assert_equal 'foobarraboof', data
|
840
|
+
end
|
841
|
+
|
842
|
+
def test_gzip_gunzip
|
843
|
+
gzipped = Polyphony.pipe
|
844
|
+
gunzipped = Polyphony.pipe
|
845
|
+
|
846
|
+
spin { File.open(__FILE__, 'r') { |f| IO.gzip(f, gzipped) }; gzipped.close }
|
847
|
+
spin { IO.gunzip(gzipped, gunzipped); gunzipped.close }
|
848
|
+
|
849
|
+
data = gunzipped.read
|
850
|
+
assert_equal IO.read(__FILE__), data
|
851
|
+
end
|
852
|
+
|
853
|
+
def test_gunzip_with_empty_info
|
854
|
+
gzipped = Polyphony.pipe
|
855
|
+
gunzipped = Polyphony.pipe
|
856
|
+
info = {}
|
857
|
+
|
858
|
+
spin {
|
859
|
+
File.open(__FILE__, 'r') { |f| IO.gzip(f, gzipped, mtime: false) }
|
860
|
+
gzipped.close
|
861
|
+
}
|
862
|
+
spin { IO.gunzip(gzipped, gunzipped, info); gunzipped.close }
|
863
|
+
|
864
|
+
data = gunzipped.read
|
865
|
+
assert_equal IO.read(__FILE__), data
|
866
|
+
assert_equal Time.at(0), info[:mtime]
|
867
|
+
assert_nil info[:orig_name]
|
868
|
+
assert_nil info[:comment]
|
869
|
+
end
|
870
|
+
|
871
|
+
def test_gunzip_with_info
|
872
|
+
src = Polyphony.pipe
|
873
|
+
gzipped = Polyphony.pipe
|
874
|
+
gunzipped = Polyphony.pipe
|
875
|
+
|
876
|
+
src_info = {
|
877
|
+
mtime: 42,
|
878
|
+
orig_name: 'foo.bar',
|
879
|
+
comment: 'hello!'
|
880
|
+
}
|
881
|
+
|
882
|
+
dest_info = {}
|
883
|
+
|
884
|
+
spin { IO.gzip(src, gzipped, src_info); gzipped.close }
|
885
|
+
spin { IO.gunzip(gzipped, gunzipped, dest_info); gunzipped.close }
|
886
|
+
|
887
|
+
src << 'foobar'
|
888
|
+
src.close
|
889
|
+
|
890
|
+
data = gunzipped.read
|
891
|
+
assert_equal 'foobar', data
|
892
|
+
assert_equal Time.at(42), dest_info[:mtime]
|
893
|
+
assert_equal 'foo.bar', dest_info[:orig_name]
|
894
|
+
assert_equal 'hello!', dest_info[:comment]
|
895
|
+
end
|
896
|
+
end
|
data/test/test_pipe.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class PipeTest < MiniTest::Test
|
6
|
+
def test_pipe_creation
|
7
|
+
pipe = Polyphony::Pipe.new
|
8
|
+
|
9
|
+
fds = pipe.fds
|
10
|
+
assert_equal 2, fds.size
|
11
|
+
assert_kind_of Integer, fds[0]
|
12
|
+
assert_kind_of Integer, fds[1]
|
13
|
+
assert_equal false, pipe.closed?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_polyphony_pipe_method
|
17
|
+
pipe = Polyphony.pipe
|
18
|
+
|
19
|
+
fds = pipe.fds
|
20
|
+
assert_equal 2, fds.size
|
21
|
+
assert_kind_of Integer, fds[0]
|
22
|
+
assert_kind_of Integer, fds[1]
|
23
|
+
assert_equal false, pipe.closed?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_pipe_splice
|
27
|
+
src = Polyphony::Pipe.new
|
28
|
+
dest = Polyphony::Pipe.new
|
29
|
+
|
30
|
+
spin {
|
31
|
+
IO.splice(src, dest, 8192)
|
32
|
+
dest.close
|
33
|
+
}
|
34
|
+
|
35
|
+
src << IO.read(__FILE__)
|
36
|
+
src.close
|
37
|
+
|
38
|
+
data = dest.read
|
39
|
+
assert_equal IO.read(__FILE__), data
|
40
|
+
end
|
41
|
+
end
|
data/test/test_socket.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.84.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -315,16 +315,6 @@ files:
|
|
315
315
|
- ext/libev/ev_win32.c
|
316
316
|
- ext/libev/ev_wrap.h
|
317
317
|
- ext/libev/test_libev_win32.c
|
318
|
-
- ext/liburing/liburing.h
|
319
|
-
- ext/liburing/liburing/README.md
|
320
|
-
- ext/liburing/liburing/barrier.h
|
321
|
-
- ext/liburing/liburing/compat.h
|
322
|
-
- ext/liburing/liburing/io_uring.h
|
323
|
-
- ext/liburing/queue.c
|
324
|
-
- ext/liburing/register.c
|
325
|
-
- ext/liburing/setup.c
|
326
|
-
- ext/liburing/syscall.c
|
327
|
-
- ext/liburing/syscall.h
|
328
318
|
- ext/polyphony/backend_common.c
|
329
319
|
- ext/polyphony/backend_common.h
|
330
320
|
- ext/polyphony/backend_io_uring.c
|
@@ -334,9 +324,10 @@ files:
|
|
334
324
|
- ext/polyphony/event.c
|
335
325
|
- ext/polyphony/extconf.rb
|
336
326
|
- ext/polyphony/fiber.c
|
327
|
+
- ext/polyphony/io_extensions.c
|
337
328
|
- ext/polyphony/libev.c
|
338
329
|
- ext/polyphony/libev.h
|
339
|
-
- ext/polyphony/
|
330
|
+
- ext/polyphony/pipe.c
|
340
331
|
- ext/polyphony/playground.c
|
341
332
|
- ext/polyphony/polyphony.c
|
342
333
|
- ext/polyphony/polyphony.h
|
@@ -350,6 +341,7 @@ files:
|
|
350
341
|
- ext/polyphony/runqueue_ring_buffer.h
|
351
342
|
- ext/polyphony/socket_extensions.c
|
352
343
|
- ext/polyphony/thread.c
|
344
|
+
- ext/polyphony/zlib_conf.rb
|
353
345
|
- ext/test_eintr.c
|
354
346
|
- lib/polyphony.rb
|
355
347
|
- lib/polyphony/adapters/fs.rb
|
@@ -376,6 +368,7 @@ files:
|
|
376
368
|
- lib/polyphony/extensions/kernel.rb
|
377
369
|
- lib/polyphony/extensions/object.rb
|
378
370
|
- lib/polyphony/extensions/openssl.rb
|
371
|
+
- lib/polyphony/extensions/pipe.rb
|
379
372
|
- lib/polyphony/extensions/process.rb
|
380
373
|
- lib/polyphony/extensions/socket.rb
|
381
374
|
- lib/polyphony/extensions/thread.rb
|
@@ -397,6 +390,7 @@ files:
|
|
397
390
|
- test/test_global_api.rb
|
398
391
|
- test/test_io.rb
|
399
392
|
- test/test_kernel.rb
|
393
|
+
- test/test_pipe.rb
|
400
394
|
- test/test_process_supervision.rb
|
401
395
|
- test/test_queue.rb
|
402
396
|
- test/test_raw_buffer.rb
|
@@ -1,73 +0,0 @@
|
|
1
|
-
/* SPDX-License-Identifier: MIT */
|
2
|
-
#ifndef LIBURING_BARRIER_H
|
3
|
-
#define LIBURING_BARRIER_H
|
4
|
-
|
5
|
-
/*
|
6
|
-
From the kernel documentation file refcount-vs-atomic.rst:
|
7
|
-
|
8
|
-
A RELEASE memory ordering guarantees that all prior loads and
|
9
|
-
stores (all po-earlier instructions) on the same CPU are completed
|
10
|
-
before the operation. It also guarantees that all po-earlier
|
11
|
-
stores on the same CPU and all propagated stores from other CPUs
|
12
|
-
must propagate to all other CPUs before the release operation
|
13
|
-
(A-cumulative property). This is implemented using
|
14
|
-
:c:func:`smp_store_release`.
|
15
|
-
|
16
|
-
An ACQUIRE memory ordering guarantees that all post loads and
|
17
|
-
stores (all po-later instructions) on the same CPU are
|
18
|
-
completed after the acquire operation. It also guarantees that all
|
19
|
-
po-later stores on the same CPU must propagate to all other CPUs
|
20
|
-
after the acquire operation executes. This is implemented using
|
21
|
-
:c:func:`smp_acquire__after_ctrl_dep`.
|
22
|
-
*/
|
23
|
-
|
24
|
-
#ifdef __cplusplus
|
25
|
-
#include <atomic>
|
26
|
-
|
27
|
-
template <typename T>
|
28
|
-
static inline void IO_URING_WRITE_ONCE(T &var, T val)
|
29
|
-
{
|
30
|
-
std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(&var),
|
31
|
-
val, std::memory_order_relaxed);
|
32
|
-
}
|
33
|
-
template <typename T>
|
34
|
-
static inline T IO_URING_READ_ONCE(const T &var)
|
35
|
-
{
|
36
|
-
return std::atomic_load_explicit(
|
37
|
-
reinterpret_cast<const std::atomic<T> *>(&var),
|
38
|
-
std::memory_order_relaxed);
|
39
|
-
}
|
40
|
-
|
41
|
-
template <typename T>
|
42
|
-
static inline void io_uring_smp_store_release(T *p, T v)
|
43
|
-
{
|
44
|
-
std::atomic_store_explicit(reinterpret_cast<std::atomic<T> *>(p), v,
|
45
|
-
std::memory_order_release);
|
46
|
-
}
|
47
|
-
|
48
|
-
template <typename T>
|
49
|
-
static inline T io_uring_smp_load_acquire(const T *p)
|
50
|
-
{
|
51
|
-
return std::atomic_load_explicit(
|
52
|
-
reinterpret_cast<const std::atomic<T> *>(p),
|
53
|
-
std::memory_order_acquire);
|
54
|
-
}
|
55
|
-
#else
|
56
|
-
#include <stdatomic.h>
|
57
|
-
|
58
|
-
#define IO_URING_WRITE_ONCE(var, val) \
|
59
|
-
atomic_store_explicit((_Atomic typeof(var) *)&(var), \
|
60
|
-
(val), memory_order_relaxed)
|
61
|
-
#define IO_URING_READ_ONCE(var) \
|
62
|
-
atomic_load_explicit((_Atomic typeof(var) *)&(var), \
|
63
|
-
memory_order_relaxed)
|
64
|
-
|
65
|
-
#define io_uring_smp_store_release(p, v) \
|
66
|
-
atomic_store_explicit((_Atomic typeof(*(p)) *)(p), (v), \
|
67
|
-
memory_order_release)
|
68
|
-
#define io_uring_smp_load_acquire(p) \
|
69
|
-
atomic_load_explicit((_Atomic typeof(*(p)) *)(p), \
|
70
|
-
memory_order_acquire)
|
71
|
-
#endif
|
72
|
-
|
73
|
-
#endif /* defined(LIBURING_BARRIER_H) */
|