Skip to content

Commit 7b721ed

Browse files
committed
sync::mpsc: reload state after spinning on CAS failure
1 parent 8c17a3e commit 7b721ed

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

library/std/src/sync/mpmc/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ impl<T> Channel<T> {
167167
token.array.stamp = tail + 1;
168168
return true;
169169
}
170-
Err(t) => {
171-
tail = t;
170+
Err(_) => {
172171
backoff.spin();
172+
tail = self.load(Ordering::Relaxed);
173173
}
174174
}
175175
} else if stamp.wrapping_add(self.one_lap) == tail + 1 {
@@ -251,8 +251,8 @@ impl<T> Channel<T> {
251251
return true;
252252
}
253253
Err(h) => {
254-
head = h;
255254
backoff.spin();
255+
head = self.head.load(Ordering::Relaxed);
256256
}
257257
}
258258
} else if stamp == head {

library/std/src/sync/mpmc/list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ impl<T> Channel<T> {
246246
token.list.offset = offset;
247247
return true;
248248
},
249-
Err(t) => {
250-
tail = t;
251-
block = self.tail.block.load(Ordering::Acquire);
249+
Err(_) => {
252250
backoff.spin();
251+
tail = self.tail.index.load(Ordering::Acquire);
252+
block = self.tail.block.load(Ordering::Acquire);
253253
}
254254
}
255255
}
@@ -351,9 +351,9 @@ impl<T> Channel<T> {
351351
return true;
352352
},
353353
Err(h) => {
354-
head = h;
355-
block = self.head.block.load(Ordering::Acquire);
356354
backoff.spin();
355+
head = self.head.index.load(Ordering::Acquire);
356+
block = self.head.block.load(Ordering::Acquire);
357357
}
358358
}
359359
}

0 commit comments

Comments
 (0)