Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "crossbeam"
version = "0.3.2"
authors = ["Aaron Turon <[email protected]>"]
version = "0.4.0"
authors = ["The Crossbeam Project Developers"]
description = "Support for lock-free data structures, synchronizers, and parallel programming"
repository = "https://github.com/crossbeam-rs/crossbeam"
documentation = "https://docs.rs/crossbeam"
Expand All @@ -10,7 +10,14 @@ license = "Apache-2.0/MIT"
categories = ["concurrency", "data-structures"]

[features]
nightly = []
default = ["use_std"]
nightly = ["crossbeam-epoch/nightly", "crossbeam-utils/nightly"]
use_std = ["crossbeam-epoch/use_std", "crossbeam-utils/use_std"]

[dependencies]
crossbeam-epoch = "0.2"
crossbeam-utils = "0.2"
crossbeam-deque = "0.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want to expose channel for now?

Copy link
Contributor Author

@jeehoonkang jeehoonkang Jan 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, crossbeam-channel should replace the two queue implementations in sync. I don't know what's the best way to do it. I omitted this migration in this PR because I think it's @stjepang's call to make.


[dev-dependencies]
rand = "0.4"
46 changes: 29 additions & 17 deletions src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,27 @@ trait Queue<T> {
}

impl<T> Queue<T> for MsQueue<T> {
fn push(&self, t: T) { self.push(t) }
fn try_pop(&self) -> Option<T> { self.try_pop() }
fn push(&self, t: T) {
self.push(t)
}
fn try_pop(&self) -> Option<T> {
self.try_pop()
}
}

impl<T> Queue<T> for SegQueue<T> {
fn push(&self, t: T) { self.push(t) }
fn try_pop(&self) -> Option<T> { self.try_pop() }
fn push(&self, t: T) {
self.push(t)
}
fn try_pop(&self) -> Option<T> {
self.try_pop()
}
}

impl<T> Queue<T> for MpscQueue<T> {
fn push(&self, t: T) { self.push(t) }
fn push(&self, t: T) {
self.push(t)
}
fn try_pop(&self) -> Option<T> {
use extra_impls::mpsc_queue::*;

Expand All @@ -57,8 +67,12 @@ impl<T> Queue<T> for MpscQueue<T> {
}

impl<T> Queue<T> for Mutex<VecDeque<T>> {
fn push(&self, t: T) { self.lock().unwrap().push_back(t) }
fn try_pop(&self) -> Option<T> { self.lock().unwrap().pop_front() }
fn push(&self, t: T) {
self.lock().unwrap().push_back(t)
}
fn try_pop(&self) -> Option<T> {
self.lock().unwrap().pop_front()
}
}

fn bench_queue_mpsc<Q: Queue<u64> + Sync>(q: Q) -> f64 {
Expand All @@ -74,7 +88,7 @@ fn bench_queue_mpsc<Q: Queue<u64> + Sync>(q: Q) -> f64 {
}

let mut count = 0;
while count < COUNT*THREADS {
while count < COUNT * THREADS {
if q.try_pop().is_some() {
count += 1;
}
Expand Down Expand Up @@ -106,14 +120,12 @@ fn bench_queue_mpmc<Q: Queue<bool> + Sync>(q: Q) -> f64 {
}
}
});
scope.spawn(move || {
loop {
if let Some(false) = qr.try_pop() { break }
scope.spawn(move || loop {
if let Some(false) = qr.try_pop() {
break;
}
});
}


});
});

Expand All @@ -135,7 +147,7 @@ fn bench_chan_mpsc() -> f64 {
});
}

for _i in 0..COUNT*THREADS {
for _i in 0..COUNT * THREADS {
let _ = rx.recv().unwrap();
}
});
Expand All @@ -153,7 +165,7 @@ fn main() {
println!("MSQ mpmc: {}", bench_queue_mpmc(MsQueue::new()));
println!("Seg mpmc: {}", bench_queue_mpmc(SegQueue::new()));

// println!("queue_mpsc: {}", bench_queue_mpsc());
// println!("queue_mpmc: {}", bench_queue_mpmc());
// println!("mutex_mpmc: {}", bench_mutex_mpmc());
// println!("queue_mpsc: {}", bench_queue_mpsc());
// println!("queue_mpmc: {}", bench_queue_mpmc());
// println!("mutex_mpmc: {}", bench_mutex_mpmc());
}
10 changes: 7 additions & 3 deletions src/bin/extra_impls/mpsc_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl<T> fmt::Debug for Queue<T> {
}
}

unsafe impl<T: Send> Send for Queue<T> { }
unsafe impl<T: Send> Sync for Queue<T> { }
unsafe impl<T: Send> Send for Queue<T> {}
unsafe impl<T: Send> Sync for Queue<T> {}

impl<T> Node<T> {
unsafe fn new(v: Option<T>) -> *mut Node<T> {
Expand Down Expand Up @@ -136,7 +136,11 @@ impl<T> Queue<T> {
return Data(ret);
}

if self.head.load(Ordering::Acquire) == tail {Empty} else {Inconsistent}
if self.head.load(Ordering::Acquire) == tail {
Empty
} else {
Inconsistent
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/bin/stress-msq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ fn main() {
let qs = q.clone();

s.spawn(move || {
for i in 1..COUNT { qs.push(i) }
for i in 1..COUNT {
qs.push(i)
}
});

for _i in 0..THREADS {
Expand Down
164 changes: 0 additions & 164 deletions src/cache_padded.rs

This file was deleted.

Loading