File tree 3 files changed +27
-9
lines changed
3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -49,3 +49,26 @@ use intrinsics;
49
49
pub unsafe fn unreachable_unchecked ( ) -> ! {
50
50
intrinsics:: unreachable ( )
51
51
}
52
+
53
+ /// Save power or switch hyperthreads in a busy-wait spin-loop.
54
+ ///
55
+ /// This function is deliberately more primitive than
56
+ /// [`std::thread::yield_now`](../../std/thread/fn.yield_now.html) and
57
+ /// does not directly yield to the system's scheduler.
58
+ /// In some cases it might be useful to use a combination of both functions.
59
+ /// Careful benchmarking is advised.
60
+ ///
61
+ /// On some platforms this function may not do anything at all.
62
+ #[ inline]
63
+ #[ unstable( feature = "renamed_spin_loop" , issue = "55002" ) ]
64
+ pub fn spin_loop ( ) {
65
+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
66
+ unsafe {
67
+ asm ! ( "pause" :: : "memory" : "volatile" ) ;
68
+ }
69
+
70
+ #[ cfg( target_arch = "aarch64" ) ]
71
+ unsafe {
72
+ asm ! ( "yield" :: : "memory" : "volatile" ) ;
73
+ }
74
+ }
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ use intrinsics;
84
84
use cell:: UnsafeCell ;
85
85
use fmt;
86
86
87
+ use hint:: spin_loop;
88
+
87
89
/// Save power or switch hyperthreads in a busy-wait spin-loop.
88
90
///
89
91
/// This function is deliberately more primitive than
@@ -96,15 +98,7 @@ use fmt;
96
98
#[ inline]
97
99
#[ stable( feature = "spin_loop_hint" , since = "1.24.0" ) ]
98
100
pub fn spin_loop_hint ( ) {
99
- #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
100
- unsafe {
101
- asm ! ( "pause" :: : "memory" : "volatile" ) ;
102
- }
103
-
104
- #[ cfg( target_arch = "aarch64" ) ]
105
- unsafe {
106
- asm ! ( "yield" :: : "memory" : "volatile" ) ;
107
- }
101
+ spin_loop ( )
108
102
}
109
103
110
104
/// A boolean type which can be safely shared between threads.
Original file line number Diff line number Diff line change 286
286
#![ feature( staged_api) ]
287
287
#![ feature( stmt_expr_attributes) ]
288
288
#![ feature( str_internals) ]
289
+ #![ feature( renamed_spin_loop) ]
289
290
#![ feature( rustc_private) ]
290
291
#![ feature( thread_local) ]
291
292
#![ feature( toowned_clone_into) ]
You can’t perform that action at this time.
0 commit comments