Skip to content

Commit

Permalink
Add no_std support to crossbeam-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Glavina committed Dec 24, 2019
1 parent 355d65f commit 9306d4d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions ci/crossbeam-queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ set -ex

export RUSTFLAGS="-D warnings"

cargo check --no-default-features
cargo check --bins --examples --tests
cargo test
9 changes: 9 additions & 0 deletions crossbeam-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ description = "Concurrent queues"
keywords = ["queue", "mpmc", "lock-free", "producer", "consumer"]
categories = ["concurrency", "data-structures"]

[features]
default = ["std"]
std = ["crossbeam-utils/std"]
alloc = ["crossbeam-utils/alloc"]

[dependencies]
cfg-if = "0.1.2"

[dependencies.crossbeam-utils]
version = "0.7"
path = "../crossbeam-utils"
default-features = false

[dev-dependencies]
rand = "0.6"
13 changes: 7 additions & 6 deletions crossbeam-queue/src/array_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
//! - Simplified BSD License and Apache License, Version 2.0
//! - http://www.1024cores.net/home/code-license

use std::cell::UnsafeCell;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ptr;
use std::sync::atomic::{self, AtomicUsize, Ordering};
use alloc::vec::Vec;
use core::cell::UnsafeCell;
use core::fmt;
use core::marker::PhantomData;
use core::mem;
use core::ptr;
use core::sync::atomic::{self, AtomicUsize, Ordering};

use crossbeam_utils::{Backoff, CachePadded};

Expand Down
9 changes: 5 additions & 4 deletions crossbeam-queue/src/err.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::error;
use std::fmt;
use core::fmt;

/// Error which occurs when popping from an empty queue.
#[derive(Clone, Copy, Eq, PartialEq)]
Expand All @@ -17,7 +16,8 @@ impl fmt::Display for PopError {
}
}

impl error::Error for PopError {
#[cfg(features = "std")]
impl std::error::Error for PopError {
fn description(&self) -> &str {
"popping from an empty queue"
}
Expand All @@ -39,7 +39,8 @@ impl<T> fmt::Display for PushError<T> {
}
}

impl<T: Send> error::Error for PushError<T> {
#[cfg(features = "std")]
impl<T: Send> std::error::Error for PushError<T> {
fn description(&self) -> &str {
"pushing into a full queue"
}
Expand Down
30 changes: 24 additions & 6 deletions crossbeam-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@

#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
#![cfg_attr(not(feature = "std"), no_std)]

#[macro_use]
extern crate cfg_if;
#[cfg(feature = "std")]
extern crate core;

cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
} else if #[cfg(feature = "std")] {
extern crate std as alloc;
}
}

extern crate crossbeam_utils;

mod array_queue;
mod err;
mod seg_queue;
cfg_if! {
if #[cfg(any(feature = "alloc", feature = "std"))] {
mod array_queue;
mod err;
mod seg_queue;

pub use self::array_queue::ArrayQueue;
pub use self::err::{PopError, PushError};
pub use self::seg_queue::SegQueue;
pub use self::array_queue::ArrayQueue;
pub use self::err::{PopError, PushError};
pub use self::seg_queue::SegQueue;
}
}
13 changes: 7 additions & 6 deletions crossbeam-queue/src/seg_queue.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::cell::UnsafeCell;
use std::fmt;
use std::marker::PhantomData;
use std::mem::{self, ManuallyDrop};
use std::ptr;
use std::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering};
use alloc::boxed::Box;
use core::cell::UnsafeCell;
use core::fmt;
use core::marker::PhantomData;
use core::mem::{self, ManuallyDrop};
use core::ptr;
use core::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering};

use crossbeam_utils::{Backoff, CachePadded};

Expand Down

0 comments on commit 9306d4d

Please sign in to comment.