Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Issue #26: Scope stats on running, completed and panicked threads #27

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 24 additions & 28 deletions benches/atomic_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,18 @@ fn concurrent_load_u8(b: &mut test::Bencher) {

thread::scope(|scope| {
for _ in 0..THREADS {
scope.spawn(|| {
loop {
start.wait();

let mut sum = 0;
for _ in 0..STEPS {
sum += a.load();
}
test::black_box(sum);

end.wait();
if exit.load() {
break;
}
scope.spawn(|| loop {
start.wait();

let mut sum = 0;
for _ in 0..STEPS {
sum += a.load();
}
test::black_box(sum);

end.wait();
if exit.load() {
break;
}
});
}
Expand Down Expand Up @@ -126,20 +124,18 @@ fn concurrent_load_usize(b: &mut test::Bencher) {

thread::scope(|scope| {
for _ in 0..THREADS {
scope.spawn(|| {
loop {
start.wait();

let mut sum = 0;
for _ in 0..STEPS {
sum += a.load();
}
test::black_box(sum);

end.wait();
if exit.load() {
break;
}
scope.spawn(|| loop {
start.wait();

let mut sum = 0;
for _ in 0..STEPS {
sum += a.load();
}
test::black_box(sum);

end.wait();
if exit.load() {
break;
}
});
}
Expand Down
36 changes: 27 additions & 9 deletions src/atomic/atomic_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,16 @@ cfg_if! {
}
}

impl_arithmetic!(usize, atomic::AtomicUsize, "let a = AtomicCell::new(7usize);");
impl_arithmetic!(isize, atomic::AtomicIsize, "let a = AtomicCell::new(7isize);");
impl_arithmetic!(
usize,
atomic::AtomicUsize,
"let a = AtomicCell::new(7usize);"
);
impl_arithmetic!(
isize,
atomic::AtomicIsize,
"let a = AtomicCell::new(7isize);"
);

impl AtomicCell<bool> {
/// Applies logical "and" to the current value and returns the previous value.
Expand Down Expand Up @@ -671,7 +679,9 @@ impl Drop for WriteGuard {
#[inline]
fn drop(&mut self) {
// Release the lock and increment the stamp.
self.lock.state.store(self.state.wrapping_add(2), Ordering::Release);
self.lock
.state
.store(self.state.wrapping_add(2), Ordering::Release);
}
}

Expand All @@ -689,7 +699,9 @@ fn lock(addr: usize) -> &'static Lock {
// The number of locks is prime.
const LEN: usize = 97;

const L: Lock = Lock { state: AtomicUsize::new(0) };
const L: Lock = Lock {
state: AtomicUsize::new(0),
};
static LOCKS: [Lock; LEN] = [
L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
Expand Down Expand Up @@ -723,7 +735,7 @@ impl AtomicUnit {
_current: (),
_new: (),
_success: Ordering,
_failure: Ordering
_failure: Ordering,
) -> Result<(), ()> {
Ok(())
}
Expand All @@ -735,7 +747,7 @@ macro_rules! atomic {
(@check, $t:ty, $atomic:ty, $a:ident, $atomic_op:expr) => {
if can_transmute::<$t, $atomic>() {
let $a: &$atomic;
break $atomic_op
break $atomic_op;
}
};

Expand All @@ -759,7 +771,7 @@ macro_rules! atomic {
atomic!(@check, $t, atomic::AtomicU64, $a, $atomic_op);
}

break $fallback_op
break $fallback_op;
}
};
}
Expand Down Expand Up @@ -909,8 +921,14 @@ mod tests {
assert_eq!(AtomicCell::<UsizeWrap>::is_lock_free(), true);

assert_eq!(AtomicCell::<u8>::is_lock_free(), cfg!(feature = "nightly"));
assert_eq!(AtomicCell::<bool>::is_lock_free(), cfg!(feature = "nightly"));
assert_eq!(AtomicCell::<U8Wrap>::is_lock_free(), cfg!(feature = "nightly"));
assert_eq!(
AtomicCell::<bool>::is_lock_free(),
cfg!(feature = "nightly")
);
assert_eq!(
AtomicCell::<U8Wrap>::is_lock_free(),
cfg!(feature = "nightly")
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/atomic/consume.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::sync::atomic::Ordering;
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
use core::sync::atomic::compiler_fence;
use core::sync::atomic::Ordering;

/// Trait which allows reading from an atomic type with "consume" ordering.
pub trait AtomicConsume {
Expand Down
2 changes: 1 addition & 1 deletion src/cache_padded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl<T> From<T> for CachePadded<T> {
#[cfg(test)]
mod test {
use super::*;
use core::mem;
use core::cell::Cell;
use core::mem;

#[test]
fn default() {
Expand Down
2 changes: 2 additions & 0 deletions src/thread.rs → src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ use std::panic;
use std::sync::{Arc, Mutex};
use std::thread;

mod stats;

/// Like [`std::thread::spawn`], but without lifetime bounds on the closure.
///
/// [`std::thread::spawn`]: https://doc.rust-lang.org/stable/std/thread/fn.spawn.html
Expand Down
Loading