Skip to content

Commit

Permalink
Remove dependency on cfg-if
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 8, 2024
1 parent 0935295 commit 35a55d2
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 210 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ crossbeam-epoch = { version = "0.9.17", path = "crossbeam-epoch", default-featur
crossbeam-queue = { version = "0.3.10", path = "crossbeam-queue", default-features = false, optional = true }
crossbeam-utils = { version = "0.8.18", path = "crossbeam-utils", default-features = false }

cfg-if = "1"

[dev-dependencies]
rand = "0.8"

Expand Down
2 changes: 0 additions & 2 deletions crossbeam-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ std = ["crossbeam-utils/std"]
[dependencies]
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }

cfg-if = "1"

[dev-dependencies]
num_cpus = "1.13.0"
rand = "0.8"
Expand Down
66 changes: 35 additions & 31 deletions crossbeam-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,36 +336,40 @@
)]
#![cfg_attr(not(feature = "std"), no_std)]

use cfg_if::cfg_if;
#[cfg(feature = "std")]
mod channel;
#[cfg(feature = "std")]
mod context;
#[cfg(feature = "std")]
mod counter;
#[cfg(feature = "std")]
mod err;
#[cfg(feature = "std")]
mod flavors;
#[cfg(feature = "std")]
mod select;
#[cfg(feature = "std")]
mod select_macro;
#[cfg(feature = "std")]
mod utils;
#[cfg(feature = "std")]
mod waker;

cfg_if! {
if #[cfg(feature = "std")] {
mod channel;
mod context;
mod counter;
mod err;
mod flavors;
mod select;
mod select_macro;
mod utils;
mod waker;

/// Crate internals used by the `select!` macro.
#[doc(hidden)]
pub mod internal {
pub use crate::select::SelectHandle;
pub use crate::select::{select, select_timeout, try_select};
}

pub use crate::channel::{after, at, never, tick};
pub use crate::channel::{bounded, unbounded};
pub use crate::channel::{IntoIter, Iter, TryIter};
pub use crate::channel::{Receiver, Sender};

pub use crate::select::{Select, SelectedOperation};

pub use crate::err::{ReadyTimeoutError, SelectTimeoutError, TryReadyError, TrySelectError};
pub use crate::err::{RecvError, RecvTimeoutError, TryRecvError};
pub use crate::err::{SendError, SendTimeoutError, TrySendError};
}
/// Crate internals used by the `select!` macro.
#[doc(hidden)]
#[cfg(feature = "std")]
pub mod internal {
pub use crate::select::{select, select_timeout, try_select, SelectHandle};
}

#[cfg(feature = "std")]
pub use crate::{
channel::{
after, at, bounded, never, tick, unbounded, IntoIter, Iter, Receiver, Sender, TryIter,
},
err::{
ReadyTimeoutError, RecvError, RecvTimeoutError, SelectTimeoutError, SendError,
SendTimeoutError, TryReadyError, TryRecvError, TrySelectError, TrySendError,
},
select::{Select, SelectedOperation},
};
2 changes: 0 additions & 2 deletions crossbeam-deque/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ std = ["crossbeam-epoch/std", "crossbeam-utils/std"]
crossbeam-epoch = { version = "0.9.17", path = "../crossbeam-epoch", default-features = false }
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }

cfg-if = "1"

[dev-dependencies]
rand = "0.8"
4 changes: 2 additions & 2 deletions crossbeam-deque/src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::slice;
use std::sync::atomic::{self, AtomicIsize, AtomicPtr, AtomicUsize, Ordering};
use std::sync::Arc;

use crate::epoch::{self, Atomic, Owned};
use crate::utils::{Backoff, CachePadded};
use crossbeam_epoch::{self as epoch, Atomic, Owned};
use crossbeam_utils::{Backoff, CachePadded};

// Minimum buffer capacity.
const MIN_CAP: usize = 64;
Expand Down
15 changes: 4 additions & 11 deletions crossbeam-deque/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@
)]
#![cfg_attr(not(feature = "std"), no_std)]

use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "std")] {
use crossbeam_epoch as epoch;
use crossbeam_utils as utils;

mod deque;
pub use crate::deque::{Injector, Steal, Stealer, Worker};
}
}
#[cfg(feature = "std")]
mod deque;
#[cfg(feature = "std")]
pub use crate::deque::{Injector, Steal, Stealer, Worker};
2 changes: 0 additions & 2 deletions crossbeam-epoch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ loom = ["loom-crate", "crossbeam-utils/loom"]
[dependencies]
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }

cfg-if = "1"

# Enable the use of loom for concurrency testing.
#
# NOTE: This feature is outside of the normal semver guarantees and minor or
Expand Down
59 changes: 29 additions & 30 deletions crossbeam-epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
#[cfg(crossbeam_loom)]
extern crate loom_crate as loom;

use cfg_if::cfg_if;

#[cfg(crossbeam_loom)]
#[allow(unused_imports, dead_code)]
mod primitive {
Expand Down Expand Up @@ -134,34 +132,35 @@ mod primitive {
pub(crate) use std::thread_local;
}

#[cfg(target_has_atomic = "ptr")]
cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
extern crate alloc;

mod atomic;
mod collector;
mod deferred;
mod epoch;
mod guard;
mod internal;
mod sync;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod atomic;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod collector;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod deferred;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod epoch;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod guard;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod internal;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod sync;

pub use self::atomic::{
Pointable, Atomic, CompareExchangeError,
Owned, Pointer, Shared,
};
pub use self::collector::{Collector, LocalHandle};
pub use self::guard::{unprotected, Guard};
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
#[allow(deprecated)]
pub use crate::atomic::{CompareAndSetError, CompareAndSetOrdering};
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
pub use crate::{
atomic::{Atomic, CompareExchangeError, Owned, Pointable, Pointer, Shared},
collector::{Collector, LocalHandle},
guard::{unprotected, Guard},
};

#[allow(deprecated)]
pub use self::atomic::{CompareAndSetError, CompareAndSetOrdering};
}
}

cfg_if! {
if #[cfg(feature = "std")] {
mod default;
pub use self::default::{default_collector, is_pinned, pin};
}
}
#[cfg(feature = "std")]
mod default;
#[cfg(feature = "std")]
pub use crate::default::{default_collector, is_pinned, pin};
2 changes: 0 additions & 2 deletions crossbeam-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ nightly = ["crossbeam-utils/nightly"]
[dependencies]
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }

cfg-if = "1"

[dev-dependencies]
rand = "0.8"
18 changes: 8 additions & 10 deletions crossbeam-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(target_has_atomic = "ptr")]
cfg_if::cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
extern crate alloc;

mod array_queue;
mod seg_queue;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod array_queue;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod seg_queue;

pub use self::array_queue::ArrayQueue;
pub use self::seg_queue::SegQueue;
}
}
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
pub use crate::{array_queue::ArrayQueue, seg_queue::SegQueue};
2 changes: 0 additions & 2 deletions crossbeam-skiplist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ alloc = ["crossbeam-epoch/alloc"]
crossbeam-epoch = { version = "0.9.17", path = "../crossbeam-epoch", default-features = false }
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }

cfg-if = "1"

[dev-dependencies]
rand = "0.8"
4 changes: 2 additions & 2 deletions crossbeam-skiplist/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use core::ops::{Bound, Deref, Index, RangeBounds};
use core::ptr;
use core::sync::atomic::{fence, AtomicUsize, Ordering};

use crate::epoch::{self, Atomic, Collector, Guard, Shared};
use crate::utils::CachePadded;
use crossbeam_epoch::{self as epoch, Atomic, Collector, Guard, Shared};
use crossbeam_utils::CachePadded;

/// Number of bits needed to store height.
const HEIGHT_BITS: usize = 5;
Expand Down
38 changes: 14 additions & 24 deletions crossbeam-skiplist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,20 @@
)]
#![cfg_attr(not(feature = "std"), no_std)]

use cfg_if::cfg_if;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
extern crate alloc;

#[cfg(target_has_atomic = "ptr")]
cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
pub mod base;
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
#[doc(inline)]
pub use crate::base::SkipList;

use crossbeam_epoch as epoch;
use crossbeam_utils as utils;
#[cfg(feature = "std")]
pub mod map;
#[cfg(feature = "std")]
pub mod set;

pub mod base;
#[doc(inline)]
pub use crate::base::SkipList;
}
}

cfg_if! {
if #[cfg(feature = "std")] {
pub mod map;
#[doc(inline)]
pub use crate::map::SkipMap;

pub mod set;
#[doc(inline)]
pub use crate::set::SkipSet;
}
}
#[cfg(feature = "std")]
#[doc(inline)]
pub use crate::{map::SkipMap, set::SkipSet};
2 changes: 1 addition & 1 deletion crossbeam-skiplist/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::ops::{Bound, RangeBounds};
use std::ptr;

use crate::base::{self, try_pin_loop};
use crate::epoch;
use crossbeam_epoch as epoch;

/// An ordered map based on a lock-free skip list.
///
Expand Down
1 change: 0 additions & 1 deletion crossbeam-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ std = []
nightly = []

[dependencies]
cfg-if = "1"

# Enable the use of loom for concurrency testing.
#
Expand Down
37 changes: 16 additions & 21 deletions crossbeam-utils/src/atomic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,28 @@
#[cfg(target_has_atomic = "ptr")]
#[cfg(not(crossbeam_loom))]
cfg_if::cfg_if! {
// Use "wide" sequence lock if the pointer width <= 32 for preventing its counter against wrap
// around.
//
// We are ignoring too wide architectures (pointer width >= 256), since such a system will not
// appear in a conceivable future.
//
// In narrow architectures (pointer width <= 16), the counter is still <= 32-bit and may be
// vulnerable to wrap around. But it's mostly okay, since in such a primitive hardware, the
// counter will not be increased that fast.
if #[cfg(any(target_pointer_width = "64", target_pointer_width = "128"))] {
mod seq_lock;
} else {
#[path = "seq_lock_wide.rs"]
mod seq_lock;
}
}
// Use "wide" sequence lock if the pointer width <= 32 for preventing its counter against wrap
// around.
//
// In narrow architectures (pointer width <= 16), the counter is still <= 32-bit and may be
// vulnerable to wrap around. But it's mostly okay, since in such a primitive hardware, the
// counter will not be increased that fast.
// Note that Rust (and C99) pointers must be at least 16-bits: https://github.com/rust-lang/rust/pull/49305
#[cfg_attr(
any(target_pointer_width = "16", target_pointer_width = "32"),
path = "seq_lock_wide.rs"
)]
mod seq_lock;

#[cfg(target_has_atomic = "ptr")]
// We cannot provide AtomicCell under cfg(crossbeam_loom) because loom's atomic
// types have a different in-memory representation than the underlying type.
// TODO: The latest loom supports fences, so fallback using seqlock may be available.
#[cfg(not(crossbeam_loom))]
mod atomic_cell;
mod consume;

#[cfg(target_has_atomic = "ptr")]
#[cfg(not(crossbeam_loom))]
pub use self::atomic_cell::AtomicCell;
pub use self::consume::AtomicConsume;
pub use atomic_cell::AtomicCell;

mod consume;
pub use consume::AtomicConsume;
14 changes: 5 additions & 9 deletions crossbeam-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@ pub use crate::cache_padded::CachePadded;
mod backoff;
pub use crate::backoff::Backoff;

use cfg_if::cfg_if;
#[cfg(feature = "std")]
pub mod sync;

cfg_if! {
if #[cfg(feature = "std")] {
pub mod sync;

#[cfg(not(crossbeam_loom))]
pub mod thread;
}
}
#[cfg(feature = "std")]
#[cfg(not(crossbeam_loom))]
pub mod thread;
Loading

0 comments on commit 35a55d2

Please sign in to comment.