Skip to content

Commit 2c8c847

Browse files
hawkwkornelski
andauthored
Replace deprecated compare_and_swap with compare_exchange (#514)
The `compare_and_swap` method on atomics is now deprecated in favor of `compare_exchange`. Since the author of #510 closed that PR, this is just #510 with rustfmt run. I also removed an unnecessary trailing semicolon that the latest rust compiler now complains about. Signed-off-by: Eliza Weisman <[email protected]> Co-authored-by: Kornel <[email protected]>
1 parent eec547d commit 2c8c847

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/proto/ping_pong.rs

+30-15
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,16 @@ impl ReceivedPing {
211211

212212
impl UserPings {
213213
pub(crate) fn send_ping(&self) -> Result<(), Option<proto::Error>> {
214-
let prev = self.0.state.compare_and_swap(
215-
USER_STATE_EMPTY, // current
216-
USER_STATE_PENDING_PING, // new
217-
Ordering::AcqRel,
218-
);
214+
let prev = self
215+
.0
216+
.state
217+
.compare_exchange(
218+
USER_STATE_EMPTY, // current
219+
USER_STATE_PENDING_PING, // new
220+
Ordering::AcqRel,
221+
Ordering::Acquire,
222+
)
223+
.unwrap_or_else(|v| v);
219224

220225
match prev {
221226
USER_STATE_EMPTY => {
@@ -234,11 +239,16 @@ impl UserPings {
234239
// Must register before checking state, in case state were to change
235240
// before we could register, and then the ping would just be lost.
236241
self.0.pong_task.register(cx.waker());
237-
let prev = self.0.state.compare_and_swap(
238-
USER_STATE_RECEIVED_PONG, // current
239-
USER_STATE_EMPTY, // new
240-
Ordering::AcqRel,
241-
);
242+
let prev = self
243+
.0
244+
.state
245+
.compare_exchange(
246+
USER_STATE_RECEIVED_PONG, // current
247+
USER_STATE_EMPTY, // new
248+
Ordering::AcqRel,
249+
Ordering::Acquire,
250+
)
251+
.unwrap_or_else(|v| v);
242252

243253
match prev {
244254
USER_STATE_RECEIVED_PONG => Poll::Ready(Ok(())),
@@ -252,11 +262,16 @@ impl UserPings {
252262

253263
impl UserPingsRx {
254264
fn receive_pong(&self) -> bool {
255-
let prev = self.0.state.compare_and_swap(
256-
USER_STATE_PENDING_PONG, // current
257-
USER_STATE_RECEIVED_PONG, // new
258-
Ordering::AcqRel,
259-
);
265+
let prev = self
266+
.0
267+
.state
268+
.compare_exchange(
269+
USER_STATE_PENDING_PONG, // current
270+
USER_STATE_RECEIVED_PONG, // new
271+
Ordering::AcqRel,
272+
Ordering::Acquire,
273+
)
274+
.unwrap_or_else(|v| v);
260275

261276
if prev == USER_STATE_PENDING_PONG {
262277
self.0.pong_task.wake();

src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ impl proto::Peer for Peer {
13711371
reason: Reason::PROTOCOL_ERROR,
13721372
});
13731373
}}
1374-
};
1374+
}
13751375

13761376
b = b.version(Version::HTTP_2);
13771377

0 commit comments

Comments
 (0)