Skip to content

Commit 55da427

Browse files
committed
Relax SeqCst in heph
This replaces all SeqCst atomic operations with Release, Acquire or AcqRel. Also see rust-lang/rust#122729.
1 parent 8dce55f commit 55da427

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/actor/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn actor_future() {
120120

121121
// Send a message and the actor should return Ok.
122122
actor_ref.try_send(()).unwrap();
123-
assert_eq!(count.load(Ordering::SeqCst), 1);
123+
assert_eq!(count.load(Ordering::Acquire), 1);
124124
let res = actor.as_mut().poll(&mut ctx);
125125
assert_eq!(res, Poll::Ready(()));
126126
}
@@ -150,7 +150,7 @@ fn erroneous_actor_process() {
150150
let res = actor.as_mut().poll(&mut ctx);
151151
assert_eq!(res, Poll::Ready(()));
152152
assert_eq!(supervisor_called_count, 1);
153-
assert_eq!(count.load(Ordering::SeqCst), 0);
153+
assert_eq!(count.load(Ordering::Acquire), 0);
154154
}
155155

156156
#[test]
@@ -170,7 +170,7 @@ fn restarting_erroneous_actor_process() {
170170
assert_eq!(res, Poll::Pending);
171171
assert_eq!(supervisor_called_count.get(), 1);
172172
// The future to wake itself after a restart to ensure it gets run again.
173-
assert_eq!(count.load(Ordering::SeqCst), 1);
173+
assert_eq!(count.load(Ordering::Acquire), 1);
174174

175175
// After a restart the actor should continue without issues.
176176
let res = actor.as_mut().poll(&mut ctx);
@@ -179,7 +179,7 @@ fn restarting_erroneous_actor_process() {
179179

180180
// Finally after sending it a message it should complete.
181181
actor_ref.try_send(()).unwrap();
182-
assert_eq!(count.load(Ordering::SeqCst), 2);
182+
assert_eq!(count.load(Ordering::Acquire), 2);
183183
let res = actor.as_mut().poll(&mut ctx);
184184
assert_eq!(res, Poll::Ready(()));
185185
assert_eq!(supervisor_called_count.get(), 1);
@@ -237,7 +237,7 @@ fn panicking_actor_process() {
237237
let res = actor.as_mut().poll(&mut ctx);
238238
assert_eq!(res, Poll::Ready(()));
239239
assert_eq!(supervisor_called_count, 1);
240-
assert_eq!(count.load(Ordering::SeqCst), 0);
240+
assert_eq!(count.load(Ordering::Acquire), 0);
241241
}
242242

243243
#[test]
@@ -284,7 +284,7 @@ fn restarting_panicking_actor_process() {
284284
assert_eq!(res, Poll::Pending);
285285
assert_eq!(supervisor_called_count.get(), 1);
286286
// The future to wake itself after a restart to ensure it gets run again.
287-
assert_eq!(count.load(Ordering::SeqCst), 1);
287+
assert_eq!(count.load(Ordering::Acquire), 1);
288288

289289
// After a restart the actor should continue without issues.
290290
let res = actor.as_mut().poll(&mut ctx);
@@ -293,7 +293,7 @@ fn restarting_panicking_actor_process() {
293293

294294
// Finally after sending it a message it should complete.
295295
actor_ref.try_send(()).unwrap();
296-
assert_eq!(count.load(Ordering::SeqCst), 2);
296+
assert_eq!(count.load(Ordering::Acquire), 2);
297297
let res = actor.as_mut().poll(&mut ctx);
298298
assert_eq!(res, Poll::Ready(()));
299299
assert_eq!(supervisor_called_count.get(), 1);
@@ -306,7 +306,7 @@ pub(crate) fn task_wake_counter() -> (task::Waker, Arc<AtomicUsize>) {
306306

307307
impl task::Wake for WakeCounter {
308308
fn wake(self: Arc<Self>) {
309-
_ = self.0.fetch_add(1, Ordering::SeqCst);
309+
_ = self.0.fetch_add(1, Ordering::AcqRel);
310310
}
311311
}
312312

src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ pub fn set_message_loss(mut percent: u8) {
4242
if percent > 100 {
4343
percent = 100;
4444
}
45-
MSG_LOSS.store(percent, Ordering::SeqCst);
45+
MSG_LOSS.store(percent, Ordering::Release);
4646
}
4747

4848
/// Returns `true` if the message should be lost.
4949
pub(crate) fn should_lose_msg() -> bool {
50-
// Safety: `Relaxed` is fine here as we'll get the update, sending a message
50+
// SAFETY: `Relaxed` is fine here as we'll get the update, sending a message
5151
// when we're not supposed to isn't too bad.
5252
let loss = MSG_LOSS.load(Ordering::Relaxed);
5353
loss != 0 || random_percentage() < loss

0 commit comments

Comments
 (0)