@@ -414,6 +414,27 @@ typedef struct SDL_AtomicInt { int value; } SDL_AtomicInt;
414
414
*/
415
415
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicInt (SDL_AtomicInt * a , int oldval , int newval );
416
416
417
+ /**
418
+ * Set an atomic variable to a new value if it is currently an old value,
419
+ * using relaxed memory ordering.
420
+ *
421
+ * ***Note: If you don't know what this function is for, you shouldn't use
422
+ * it!***
423
+ *
424
+ * \param a a pointer to an SDL_AtomicInt variable to be modified.
425
+ * \param oldval the old value.
426
+ * \param newval the new value.
427
+ * \returns true if the atomic variable was set, false otherwise.
428
+ *
429
+ * \threadsafety It is safe to call this function from any thread.
430
+ *
431
+ * \since This function is available since SDL 3.4.0.
432
+ *
433
+ * \sa SDL_GetRelaxedAtomicInt
434
+ * \sa SDL_SetRelaxedAtomicInt
435
+ */
436
+ extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapRelaxedAtomicInt (SDL_AtomicInt * a , int oldval , int newval );
437
+
417
438
/**
418
439
* Set an atomic variable to a value.
419
440
*
@@ -434,6 +455,24 @@ extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicInt(SDL_AtomicInt *a, i
434
455
*/
435
456
extern SDL_DECLSPEC int SDLCALL SDL_SetAtomicInt (SDL_AtomicInt * a , int v );
436
457
458
+ /**
459
+ * Set an atomic variable to a value using relaxed memory ordering.
460
+ *
461
+ * ***Note: If you don't know what this function is for, you shouldn't use
462
+ * it!***
463
+ *
464
+ * \param a a pointer to an SDL_AtomicInt variable to be modified.
465
+ * \param v the desired value.
466
+ * \returns the previous value of the atomic variable.
467
+ *
468
+ * \threadsafety It is safe to call this function from any thread.
469
+ *
470
+ * \since This function is available since SDL 3.4.0.
471
+ *
472
+ * \sa SDL_GetRelaxedAtomicInt
473
+ */
474
+ extern SDL_DECLSPEC int SDLCALL SDL_SetRelaxedAtomicInt (SDL_AtomicInt * a , int v );
475
+
437
476
/**
438
477
* Get the value of an atomic variable.
439
478
*
@@ -451,6 +490,23 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAtomicInt(SDL_AtomicInt *a, int v);
451
490
*/
452
491
extern SDL_DECLSPEC int SDLCALL SDL_GetAtomicInt (SDL_AtomicInt * a );
453
492
493
+ /**
494
+ * Get the value of an atomic variable using relaxed memory ordering.
495
+ *
496
+ * ***Note: If you don't know what this function is for, you shouldn't use
497
+ * it!***
498
+ *
499
+ * \param a a pointer to an SDL_AtomicInt variable.
500
+ * \returns the current value of an atomic variable.
501
+ *
502
+ * \threadsafety It is safe to call this function from any thread.
503
+ *
504
+ * \since This function is available since SDL 3.4.0.
505
+ *
506
+ * \sa SDL_SetRelaxedAtomicInt
507
+ */
508
+ extern SDL_DECLSPEC int SDLCALL SDL_GetRelaxedAtomicInt (SDL_AtomicInt * a );
509
+
454
510
/**
455
511
* Add to an atomic variable.
456
512
*
@@ -472,6 +528,25 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAtomicInt(SDL_AtomicInt *a);
472
528
*/
473
529
extern SDL_DECLSPEC int SDLCALL SDL_AddAtomicInt (SDL_AtomicInt * a , int v );
474
530
531
+ /**
532
+ * Add to an atomic variable using relaxed memory ordering.
533
+ *
534
+ * ***Note: If you don't know what this function is for, you shouldn't use
535
+ * it!***
536
+ *
537
+ * \param a a pointer to an SDL_AtomicInt variable to be modified.
538
+ * \param v the desired value to add.
539
+ * \returns the previous value of the atomic variable.
540
+ *
541
+ * \threadsafety It is safe to call this function from any thread.
542
+ *
543
+ * \since This function is available since SDL 3.4.0.
544
+ *
545
+ * \sa SDL_RelaxedAtomicDecRef
546
+ * \sa SDL_RelaxedAtomicIncRef
547
+ */
548
+ extern SDL_DECLSPEC int SDLCALL SDL_AddRelaxedAtomicInt (SDL_AtomicInt * a , int v );
549
+
475
550
#ifndef SDL_AtomicIncRef
476
551
477
552
/**
@@ -491,6 +566,25 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddAtomicInt(SDL_AtomicInt *a, int v);
491
566
#define SDL_AtomicIncRef (a ) SDL_AddAtomicInt(a, 1)
492
567
#endif
493
568
569
+ #ifndef SDL_RelaxedAtomicIncRef
570
+
571
+ /**
572
+ * Increment an atomic variable used as a reference count, using relaxed memory ordering.
573
+ *
574
+ * ***Note: If you don't know what this macro is for, you shouldn't use it!***
575
+ *
576
+ * \param a a pointer to an SDL_AtomicInt to increment.
577
+ * \returns the previous value of the atomic variable.
578
+ *
579
+ * \threadsafety It is safe to call this macro from any thread.
580
+ *
581
+ * \since This macro is available since SDL 3.4.0.
582
+ *
583
+ * \sa SDL_RelaxedAtomicDecRef
584
+ */
585
+ #define SDL_RelaxedAtomicIncRef (a ) SDL_AddRelaxedAtomicInt(a, 1)
586
+ #endif
587
+
494
588
#ifndef SDL_AtomicDecRef
495
589
496
590
/**
@@ -511,6 +605,26 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddAtomicInt(SDL_AtomicInt *a, int v);
511
605
#define SDL_AtomicDecRef (a ) (SDL_AddAtomicInt(a, -1) == 1)
512
606
#endif
513
607
608
+ #ifndef SDL_RelaxedAtomicDecRef
609
+
610
+ /**
611
+ * Decrement an atomic variable used as a reference count, using relaxed memory ordering.
612
+ *
613
+ * ***Note: If you don't know what this macro is for, you shouldn't use it!***
614
+ *
615
+ * \param a a pointer to an SDL_AtomicInt to decrement.
616
+ * \returns true if the variable reached zero after decrementing, false
617
+ * otherwise.
618
+ *
619
+ * \threadsafety It is safe to call this macro from any thread.
620
+ *
621
+ * \since This macro is available since SDL 3.4.0.
622
+ *
623
+ * \sa SDL_AtomicIncRef
624
+ */
625
+ #define SDL_RelaxedAtomicDecRef (a ) (SDL_AddRelaxedAtomicInt(a, -1) == 1)
626
+ #endif
627
+
514
628
/**
515
629
* A type representing an atomic unsigned 32-bit value.
516
630
*
@@ -559,6 +673,27 @@ typedef struct SDL_AtomicU32 { Uint32 value; } SDL_AtomicU32;
559
673
*/
560
674
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicU32 (SDL_AtomicU32 * a , Uint32 oldval , Uint32 newval );
561
675
676
+ /**
677
+ * Set an atomic variable to a new value if it is currently an old value,
678
+ * using relaxed memory ordering.
679
+ *
680
+ * ***Note: If you don't know what this function is for, you shouldn't use
681
+ * it!***
682
+ *
683
+ * \param a a pointer to an SDL_AtomicU32 variable to be modified.
684
+ * \param oldval the old value.
685
+ * \param newval the new value.
686
+ * \returns true if the atomic variable was set, false otherwise.
687
+ *
688
+ * \threadsafety It is safe to call this function from any thread.
689
+ *
690
+ * \since This function is available since SDL 3.4.0.
691
+ *
692
+ * \sa SDL_GetRelaxedAtomicU32
693
+ * \sa SDL_SetRelaxedAtomicU32
694
+ */
695
+ extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapRelaxedAtomicU32 (SDL_AtomicU32 * a , Uint32 oldval , Uint32 newval );
696
+
562
697
/**
563
698
* Set an atomic variable to a value.
564
699
*
@@ -579,6 +714,24 @@ extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, U
579
714
*/
580
715
extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetAtomicU32 (SDL_AtomicU32 * a , Uint32 v );
581
716
717
+ /**
718
+ * Set an atomic variable to a value using relaxed memory ordering.
719
+ *
720
+ * ***Note: If you don't know what this function is for, you shouldn't use
721
+ * it!***
722
+ *
723
+ * \param a a pointer to an SDL_AtomicU32 variable to be modified.
724
+ * \param v the desired value.
725
+ * \returns the previous value of the atomic variable.
726
+ *
727
+ * \threadsafety It is safe to call this function from any thread.
728
+ *
729
+ * \since This function is available since SDL 3.4.0.
730
+ *
731
+ * \sa SDL_GetRelaxedAtomicU32
732
+ */
733
+ extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetRelaxedAtomicU32 (SDL_AtomicU32 * a , Uint32 v );
734
+
582
735
/**
583
736
* Get the value of an atomic variable.
584
737
*
@@ -596,6 +749,23 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_SetAtomicU32(SDL_AtomicU32 *a, Uint32 v);
596
749
*/
597
750
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAtomicU32 (SDL_AtomicU32 * a );
598
751
752
+ /**
753
+ * Get the value of an atomic variable using relaxed memory ordering.
754
+ *
755
+ * ***Note: If you don't know what this function is for, you shouldn't use
756
+ * it!***
757
+ *
758
+ * \param a a pointer to an SDL_AtomicU32 variable.
759
+ * \returns the current value of an atomic variable.
760
+ *
761
+ * \threadsafety It is safe to call this function from any thread.
762
+ *
763
+ * \since This function is available since SDL 3.4.0.
764
+ *
765
+ * \sa SDL_SetRelaxedAtomicU32
766
+ */
767
+ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetRelaxedAtomicU32 (SDL_AtomicU32 * a );
768
+
599
769
/**
600
770
* Add to an atomic variable.
601
771
*
@@ -614,6 +784,22 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAtomicU32(SDL_AtomicU32 *a);
614
784
*/
615
785
extern SDL_DECLSPEC Uint32 SDLCALL SDL_AddAtomicU32 (SDL_AtomicU32 * a , int v );
616
786
787
+ /**
788
+ * Add to an atomic variable using relaxed memory ordering.
789
+ *
790
+ * ***Note: If you don't know what this function is for, you shouldn't use
791
+ * it!***
792
+ *
793
+ * \param a a pointer to an SDL_AtomicU32 variable to be modified.
794
+ * \param v the desired value to add or subtract.
795
+ * \returns the previous value of the atomic variable.
796
+ *
797
+ * \threadsafety It is safe to call this function from any thread.
798
+ *
799
+ * \since This function is available since SDL 3.4.0.
800
+ */
801
+ extern SDL_DECLSPEC Uint32 SDLCALL SDL_AddRelaxedAtomicU32 (SDL_AtomicU32 * a , int v );
802
+
617
803
/**
618
804
* Set a pointer to a new value if it is currently an old value.
619
805
*
@@ -635,6 +821,28 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_AddAtomicU32(SDL_AtomicU32 *a, int v);
635
821
*/
636
822
extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicPointer (void * * a , void * oldval , void * newval );
637
823
824
+ /**
825
+ * Set a pointer to a new value if it is currently an old value,
826
+ * using relaxed memory ordering.
827
+ *
828
+ * ***Note: If you don't know what this function is for, you shouldn't use
829
+ * it!***
830
+ *
831
+ * \param a a pointer to a pointer.
832
+ * \param oldval the old pointer value.
833
+ * \param newval the new pointer value.
834
+ * \returns true if the pointer was set, false otherwise.
835
+ *
836
+ * \threadsafety It is safe to call this function from any thread.
837
+ *
838
+ * \since This function is available since SDL 3.4.0.
839
+ *
840
+ * \sa SDL_CompareAndSwapRelaxedAtomicInt
841
+ * \sa SDL_GetRelaxedAtomicPointer
842
+ * \sa SDL_SetRelaxedAtomicPointer
843
+ */
844
+ extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapRelaxedAtomicPointer (void * * a , void * oldval , void * newval );
845
+
638
846
/**
639
847
* Set a pointer to a value atomically.
640
848
*
@@ -654,6 +862,25 @@ extern SDL_DECLSPEC bool SDLCALL SDL_CompareAndSwapAtomicPointer(void **a, void
654
862
*/
655
863
extern SDL_DECLSPEC void * SDLCALL SDL_SetAtomicPointer (void * * a , void * v );
656
864
865
+ /**
866
+ * Set a pointer to a value atomically using relaxed memory ordering.
867
+ *
868
+ * ***Note: If you don't know what this function is for, you shouldn't use
869
+ * it!***
870
+ *
871
+ * \param a a pointer to a pointer.
872
+ * \param v the desired pointer value.
873
+ * \returns the previous value of the pointer.
874
+ *
875
+ * \threadsafety It is safe to call this function from any thread.
876
+ *
877
+ * \since This function is available since SDL 3.4.0.
878
+ *
879
+ * \sa SDL_CompareAndSwapRelaxedAtomicPointer
880
+ * \sa SDL_GetRelaxedAtomicPointer
881
+ */
882
+ extern SDL_DECLSPEC void * SDLCALL SDL_SetRelaxedAtomicPointer (void * * a , void * v );
883
+
657
884
/**
658
885
* Get the value of a pointer atomically.
659
886
*
@@ -672,6 +899,24 @@ extern SDL_DECLSPEC void * SDLCALL SDL_SetAtomicPointer(void **a, void *v);
672
899
*/
673
900
extern SDL_DECLSPEC void * SDLCALL SDL_GetAtomicPointer (void * * a );
674
901
902
+ /**
903
+ * Get the value of a pointer atomically using relaxed memory ordering.
904
+ *
905
+ * ***Note: If you don't know what this function is for, you shouldn't use
906
+ * it!***
907
+ *
908
+ * \param a a pointer to a pointer.
909
+ * \returns the current value of a pointer.
910
+ *
911
+ * \threadsafety It is safe to call this function from any thread.
912
+ *
913
+ * \since This function is available since SDL 3.4.0.
914
+ *
915
+ * \sa SDL_CompareAndSwapRelaxedAtomicPointer
916
+ * \sa SDL_SetRelaxedAtomicPointer
917
+ */
918
+ extern SDL_DECLSPEC void * SDLCALL SDL_GetRelaxedAtomicPointer (void * * a );
919
+
675
920
/* Ends C function definitions when using C++ */
676
921
#ifdef __cplusplus
677
922
}
0 commit comments