@@ -64,7 +64,7 @@ impl<T> Buffer<T> {
64
64
/// that would be more expensive and difficult to implement generically for all types `T`.
65
65
/// Hence, as a hack, we use a volatile write instead.
66
66
unsafe fn write ( & self , index : isize , task : MaybeUninit < T > ) {
67
- ptr:: write_volatile ( self . at ( index) as * mut MaybeUninit < T > , task)
67
+ ptr:: write_volatile ( self . at ( index) . cast :: < MaybeUninit < T > > ( ) , task)
68
68
}
69
69
70
70
/// Reads a task from the specified `index`.
@@ -74,7 +74,7 @@ impl<T> Buffer<T> {
74
74
/// that would be more expensive and difficult to implement generically for all types `T`.
75
75
/// Hence, as a hack, we use a volatile load instead.
76
76
unsafe fn read ( & self , index : isize ) -> MaybeUninit < T > {
77
- ptr:: read_volatile ( self . at ( index) as * mut MaybeUninit < T > )
77
+ ptr:: read_volatile ( self . at ( index) . cast :: < MaybeUninit < T > > ( ) )
78
78
}
79
79
}
80
80
@@ -1119,6 +1119,11 @@ struct Slot<T> {
1119
1119
}
1120
1120
1121
1121
impl < T > Slot < T > {
1122
+ const UNINIT : Self = Self {
1123
+ task : UnsafeCell :: new ( MaybeUninit :: uninit ( ) ) ,
1124
+ state : AtomicUsize :: new ( 0 ) ,
1125
+ } ;
1126
+
1122
1127
/// Waits until a task is written into the slot.
1123
1128
fn wait_write ( & self ) {
1124
1129
let backoff = Backoff :: new ( ) ;
@@ -1142,13 +1147,10 @@ struct Block<T> {
1142
1147
impl < T > Block < T > {
1143
1148
/// Creates an empty block that starts at `start_index`.
1144
1149
fn new ( ) -> Block < T > {
1145
- // SAFETY: This is safe because:
1146
- // [1] `Block::next` (AtomicPtr) may be safely zero initialized.
1147
- // [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4].
1148
- // [3] `Slot::task` (UnsafeCell) may be safely zero initialized because it
1149
- // holds a MaybeUninit.
1150
- // [4] `Slot::state` (AtomicUsize) may be safely zero initialized.
1151
- unsafe { MaybeUninit :: zeroed ( ) . assume_init ( ) }
1150
+ Self {
1151
+ next : AtomicPtr :: new ( ptr:: null_mut ( ) ) ,
1152
+ slots : [ Slot :: UNINIT ; BLOCK_CAP ] ,
1153
+ }
1152
1154
}
1153
1155
1154
1156
/// Waits until the next pointer is set.
0 commit comments