@@ -35,8 +35,6 @@ impl LazyUsize {
35
35
36
36
// The initialization is not completed.
37
37
pub const UNINIT : usize = usize:: max_value ( ) ;
38
- // The initialization is currently running.
39
- pub const ACTIVE : usize = usize:: max_value ( ) - 1 ;
40
38
41
39
// Runs the init() function at least once, returning the value of some run
42
40
// of init(). Multiple callers can run their init() functions in parallel.
@@ -50,36 +48,6 @@ impl LazyUsize {
50
48
}
51
49
val
52
50
}
53
-
54
- // Synchronously runs the init() function. Only one caller will have their
55
- // init() function running at a time, and exactly one successful call will
56
- // be run. init() returning UNINIT or ACTIVE will be considered a failure,
57
- // and future calls to sync_init will rerun their init() function.
58
- pub fn sync_init ( & self , init : impl FnOnce ( ) -> usize , mut wait : impl FnMut ( ) ) -> usize {
59
- // Common and fast path with no contention. Don't wast time on CAS.
60
- match self . 0 . load ( Relaxed ) {
61
- Self :: UNINIT | Self :: ACTIVE => { }
62
- val => return val,
63
- }
64
- // Relaxed ordering is fine, as we only have a single atomic variable.
65
- loop {
66
- match self . 0 . compare_and_swap ( Self :: UNINIT , Self :: ACTIVE , Relaxed ) {
67
- Self :: UNINIT => {
68
- let val = init ( ) ;
69
- self . 0 . store (
70
- match val {
71
- Self :: UNINIT | Self :: ACTIVE => Self :: UNINIT ,
72
- val => val,
73
- } ,
74
- Relaxed ,
75
- ) ;
76
- return val;
77
- }
78
- Self :: ACTIVE => wait ( ) ,
79
- val => return val,
80
- }
81
- }
82
- }
83
51
}
84
52
85
53
// Identical to LazyUsize except with bool instead of usize.
0 commit comments