Skip to content

Commit

Permalink
Drop atomic dependency
Browse files Browse the repository at this point in the history
Replace `atomic::Atomic<u64>` by `std::sync::atomic:AtomicU64`.

The original motivation of using `atomic::Atomic<u64>` instead of
`std`'s version in libp2p#1670 was the following:

> I used the atomic crate and an Atomic<u64> because the AtomicU64 type
> isn't available on all architectures. The atomic crate automatically
> falls back to using a Mutex on platforms that don't support AtomicU64.

This argumentation is moot because the crate directly depends on
`libp2p-core` which also uses `AtomicU64`.
  • Loading branch information
hrxi committed May 11, 2022
1 parent f04f6bb commit 2b1671a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ serde = ["libp2p-core/serde", "libp2p-kad/serde", "libp2p-gossipsub/serde"]
all-features = true

[dependencies]
atomic = "0.5.0"
bytes = "1"
futures = "0.3.1"
futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` feature
Expand Down
14 changes: 8 additions & 6 deletions src/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::{
Multiaddr,
};

use atomic::Atomic;
use futures::{
io::{IoSlice, IoSliceMut},
prelude::*,
Expand All @@ -36,7 +35,10 @@ use std::{
convert::TryFrom as _,
io,
pin::Pin,
sync::{atomic::Ordering, Arc},
sync::{
atomic::{AtomicU64, Ordering},
Arc,
},
task::{Context, Poll},
};

Expand All @@ -52,8 +54,8 @@ impl<TInner> BandwidthLogging<TInner> {
/// Creates a new [`BandwidthLogging`] around the transport.
pub fn new(inner: TInner) -> (Self, Arc<BandwidthSinks>) {
let sink = Arc::new(BandwidthSinks {
inbound: Atomic::new(0),
outbound: Atomic::new(0),
inbound: AtomicU64::new(0),
outbound: AtomicU64::new(0),
});

let trans = BandwidthLogging {
Expand Down Expand Up @@ -165,8 +167,8 @@ impl<TInner: TryFuture> Future for BandwidthFuture<TInner> {

/// Allows obtaining the average bandwidth of the connections created from a [`BandwidthLogging`].
pub struct BandwidthSinks {
inbound: Atomic<u64>,
outbound: Atomic<u64>,
inbound: AtomicU64,
outbound: AtomicU64,
}

impl BandwidthSinks {
Expand Down

0 comments on commit 2b1671a

Please sign in to comment.