30
30
//!
31
31
//! The atomic intrinsics provide common atomic operations on machine
32
32
//! words, with multiple possible memory orderings. See the
33
- //! [atomic types][crate::sync:: atomic] docs for details.
33
+ //! [atomic types][atomic] docs for details.
34
34
//!
35
35
//! # Unwinding
36
36
//!
50
50
) ]
51
51
#![ allow( missing_docs) ]
52
52
53
- use crate :: marker:: { DiscriminantKind , Tuple } ;
53
+ use crate :: marker:: { ConstParamTy , DiscriminantKind , Tuple } ;
54
54
use crate :: ptr;
55
55
56
56
pub mod fallback;
@@ -62,6 +62,20 @@ pub mod simd;
62
62
#[ cfg( all( target_has_atomic = "8" , target_has_atomic = "32" , target_has_atomic = "ptr" ) ) ]
63
63
use crate :: sync:: atomic:: { self , AtomicBool , AtomicI32 , AtomicIsize , AtomicU32 , Ordering } ;
64
64
65
+ /// A type for atomic ordering parameters for intrinsics. This is a separate type from
66
+ /// `atomic::Ordering` so that we can make it `ConstParamTy` and fix the values used here without a
67
+ /// risk of leaking that to stable code.
68
+ #[ derive( Debug , ConstParamTy , PartialEq , Eq ) ]
69
+ pub enum AtomicOrdering {
70
+ // These values must match the compiler's `AtomicOrdering` defined in
71
+ // `rustc_middle/src/ty/consts/int.rs`!
72
+ Relaxed = 0 ,
73
+ Release = 1 ,
74
+ Acquire = 2 ,
75
+ AcqRel = 3 ,
76
+ SeqCst = 4 ,
77
+ }
78
+
65
79
// N.B., these intrinsics take raw pointers because they mutate aliased
66
80
// memory, which is not valid for either `&` or `&mut`.
67
81
@@ -391,6 +405,15 @@ pub unsafe fn atomic_cxchgweak_seqcst_acquire<T: Copy>(dst: *mut T, old: T, src:
391
405
#[ rustc_nounwind]
392
406
pub unsafe fn atomic_cxchgweak_seqcst_seqcst < T : Copy > ( dst : * mut T , old : T , src : T ) -> ( T , bool ) ;
393
407
408
+ /// Loads the current value of the pointer.
409
+ /// `T` must be an integer or pointer type.
410
+ ///
411
+ /// The stabilized version of this intrinsic is available on the
412
+ /// [`atomic`] types via the `load` method. For example, [`AtomicBool::load`].
413
+ #[ rustc_intrinsic]
414
+ #[ rustc_nounwind]
415
+ #[ cfg( not( bootstrap) ) ]
416
+ pub unsafe fn atomic_load < T : Copy , const ORD : AtomicOrdering > ( src : * const T ) -> T ;
394
417
/// Loads the current value of the pointer.
395
418
/// `T` must be an integer or pointer type.
396
419
///
@@ -399,6 +422,7 @@ pub unsafe fn atomic_cxchgweak_seqcst_seqcst<T: Copy>(dst: *mut T, old: T, src:
399
422
/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::load`].
400
423
#[ rustc_intrinsic]
401
424
#[ rustc_nounwind]
425
+ #[ cfg( bootstrap) ]
402
426
pub unsafe fn atomic_load_seqcst < T : Copy > ( src : * const T ) -> T ;
403
427
/// Loads the current value of the pointer.
404
428
/// `T` must be an integer or pointer type.
@@ -408,6 +432,7 @@ pub unsafe fn atomic_load_seqcst<T: Copy>(src: *const T) -> T;
408
432
/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::load`].
409
433
#[ rustc_intrinsic]
410
434
#[ rustc_nounwind]
435
+ #[ cfg( bootstrap) ]
411
436
pub unsafe fn atomic_load_acquire < T : Copy > ( src : * const T ) -> T ;
412
437
/// Loads the current value of the pointer.
413
438
/// `T` must be an integer or pointer type.
@@ -417,6 +442,7 @@ pub unsafe fn atomic_load_acquire<T: Copy>(src: *const T) -> T;
417
442
/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::load`].
418
443
#[ rustc_intrinsic]
419
444
#[ rustc_nounwind]
445
+ #[ cfg( bootstrap) ]
420
446
pub unsafe fn atomic_load_relaxed < T : Copy > ( src : * const T ) -> T ;
421
447
422
448
/// Stores the value at the specified memory location.
0 commit comments