@@ -77,6 +77,9 @@ typedef unsigned int rb_atomic_t;
77
77
typedef LONG rb_atomic_t ;
78
78
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
79
79
typedef unsigned int rb_atomic_t ;
80
+ #elif defined(HAVE_STDATOMIC_H)
81
+ # include < stdatomic.h>
82
+ typedef unsigned int rb_atomic_t ;
80
83
#else
81
84
# error No atomic operation found
82
85
#endif
@@ -408,6 +411,9 @@ rbimpl_atomic_fetch_add(volatile rb_atomic_t *ptr, rb_atomic_t val)
408
411
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
409
412
return atomic_add_int_nv(ptr, val) - val;
410
413
414
+ #elif defined(HAVE_STDATOMIC_H)
415
+ return atomic_fetch_add((_Atomic volatile rb_atomic_t *)ptr, val);
416
+
411
417
#else
412
418
# error Unsupported platform.
413
419
#endif
@@ -442,6 +448,9 @@ rbimpl_atomic_size_fetch_add(volatile size_t *ptr, size_t val)
442
448
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
443
449
rbimpl_atomic_fetch_add(tmp, val);
444
450
451
+ #elif defined(HAVE_STDATOMIC_H)
452
+ return atomic_fetch_add((_Atomic volatile size_t *)ptr, val);
453
+
445
454
#else
446
455
# error Unsupported platform.
447
456
#endif
@@ -479,6 +488,9 @@ rbimpl_atomic_add(volatile rb_atomic_t *ptr, rb_atomic_t val)
479
488
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
480
489
atomic_add_int(ptr, val);
481
490
491
+ #elif defined(HAVE_STDATOMIC_H)
492
+ *(_Atomic volatile rb_atomic_t *)ptr += val;
493
+
482
494
#else
483
495
# error Unsupported platform.
484
496
#endif
@@ -513,6 +525,9 @@ rbimpl_atomic_size_add(volatile size_t *ptr, size_t val)
513
525
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
514
526
rbimpl_atomic_add(tmp, val);
515
527
528
+ #elif defined(HAVE_STDATOMIC_H)
529
+ *(_Atomic volatile size_t *)ptr += val;
530
+
516
531
#else
517
532
# error Unsupported platform.
518
533
#endif
@@ -535,6 +550,9 @@ rbimpl_atomic_inc(volatile rb_atomic_t *ptr)
535
550
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
536
551
atomic_inc_uint(ptr);
537
552
553
+ #elif defined(HAVE_STDATOMIC_H)
554
+ rbimpl_atomic_add(ptr, 1);
555
+
538
556
#else
539
557
# error Unsupported platform.
540
558
#endif
@@ -562,6 +580,9 @@ rbimpl_atomic_size_inc(volatile size_t *ptr)
562
580
563
581
rbimpl_atomic_size_add(ptr, 1);
564
582
583
+ #elif defined(HAVE_STDATOMIC_H)
584
+ rbimpl_atomic_size_add(ptr, 1);
585
+
565
586
#else
566
587
# error Unsupported platform.
567
588
#endif
@@ -591,6 +612,9 @@ rbimpl_atomic_fetch_sub(volatile rb_atomic_t *ptr, rb_atomic_t val)
591
612
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
592
613
return atomic_add_int_nv(ptr, neg * val) + val;
593
614
615
+ #elif defined(HAVE_STDATOMIC_H)
616
+ return atomic_fetch_sub((_Atomic volatile rb_atomic_t *)ptr, val);
617
+
594
618
#else
595
619
# error Unsupported platform.
596
620
#endif
@@ -618,6 +642,9 @@ rbimpl_atomic_sub(volatile rb_atomic_t *ptr, rb_atomic_t val)
618
642
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
619
643
atomic_add_int(ptr, neg * val);
620
644
645
+ #elif defined(HAVE_STDATOMIC_H)
646
+ *(_Atomic volatile rb_atomic_t *)ptr -= val;
647
+
621
648
#else
622
649
# error Unsupported platform.
623
650
#endif
@@ -652,6 +679,9 @@ rbimpl_atomic_size_sub(volatile size_t *ptr, size_t val)
652
679
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
653
680
rbimpl_atomic_sub(tmp, val);
654
681
682
+ #elif defined(HAVE_STDATOMIC_H)
683
+ *(_Atomic volatile size_t *)ptr -= val;
684
+
655
685
#else
656
686
# error Unsupported platform.
657
687
#endif
@@ -674,6 +704,9 @@ rbimpl_atomic_dec(volatile rb_atomic_t *ptr)
674
704
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
675
705
atomic_dec_uint(ptr);
676
706
707
+ #elif defined(HAVE_STDATOMIC_H)
708
+ rbimpl_atomic_sub(ptr, 1);
709
+
677
710
#else
678
711
# error Unsupported platform.
679
712
#endif
@@ -701,6 +734,9 @@ rbimpl_atomic_size_dec(volatile size_t *ptr)
701
734
702
735
rbimpl_atomic_size_sub(ptr, 1);
703
736
737
+ #elif defined(HAVE_STDATOMIC_H)
738
+ rbimpl_atomic_size_sub(ptr, 1);
739
+
704
740
#else
705
741
# error Unsupported platform.
706
742
#endif
@@ -739,6 +775,9 @@ rbimpl_atomic_or(volatile rb_atomic_t *ptr, rb_atomic_t val)
739
775
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
740
776
atomic_or_uint(ptr, val);
741
777
778
+ #elif !defined(_WIN32) && defined(HAVE_STDATOMIC_H)
779
+ *(_Atomic volatile rb_atomic_t *)ptr |= val;
780
+
742
781
#else
743
782
# error Unsupported platform.
744
783
#endif
@@ -773,6 +812,9 @@ rbimpl_atomic_exchange(volatile rb_atomic_t *ptr, rb_atomic_t val)
773
812
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
774
813
return atomic_swap_uint(ptr, val);
775
814
815
+ #elif defined(HAVE_STDATOMIC_H)
816
+ return atomic_exchange((_Atomic volatile rb_atomic_t *)ptr, val);
817
+
776
818
#else
777
819
# error Unsupported platform.
778
820
#endif
@@ -805,6 +847,9 @@ rbimpl_atomic_size_exchange(volatile size_t *ptr, size_t val)
805
847
const rb_atomic_t ret = rbimpl_atomic_exchange(tmp, val);
806
848
return RBIMPL_CAST((size_t)ret);
807
849
850
+ #elif defined(HAVE_STDATOMIC_H)
851
+ return atomic_exchange((_Atomic volatile size_t *)ptr, val);
852
+
808
853
#else
809
854
# error Unsupported platform.
810
855
#endif
@@ -957,6 +1002,11 @@ rbimpl_atomic_cas(volatile rb_atomic_t *ptr, rb_atomic_t oldval, rb_atomic_t new
957
1002
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
958
1003
return atomic_cas_uint(ptr, oldval, newval);
959
1004
1005
+ #elif defined(HAVE_STDATOMIC_H)
1006
+ atomic_compare_exchange_strong(
1007
+ (_Atomic volatile rb_atomic_t *)ptr, &oldval, newval);
1008
+ return oldval;
1009
+
960
1010
#else
961
1011
# error Unsupported platform.
962
1012
#endif
@@ -999,6 +1049,11 @@ rbimpl_atomic_size_cas(volatile size_t *ptr, size_t oldval, size_t newval)
999
1049
volatile rb_atomic_t *tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
1000
1050
return rbimpl_atomic_cas(tmp, oldval, newval);
1001
1051
1052
+ #elif defined(HAVE_STDATOMIC_H)
1053
+ atomic_compare_exchange_strong(
1054
+ (_Atomic volatile size_t *)ptr, &oldval, newval);
1055
+ return oldval;
1056
+
1002
1057
#else
1003
1058
# error Unsupported platform.
1004
1059
#endif
0 commit comments