Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeehoonkang committed May 23, 2020
1 parent 33b9232 commit 1383018
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 48 deletions.
5 changes: 2 additions & 3 deletions crossbeam-epoch/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use core::fmt;
use core::marker::PhantomData;
use core::mem;
use core::ops::{Deref, DerefMut};
use core::ptr;
use core::sync::atomic::{AtomicUsize, Ordering};

use crate::guard::Guard;
Expand Down Expand Up @@ -233,7 +232,7 @@ impl<T> Atomic<T> {
/// a.store(Shared::null(), SeqCst);
/// a.store(Owned::new(1234), SeqCst);
/// ```
pub fn store<'g, P: Pointer<T>>(&self, new: P, ord: Ordering) {
pub fn store<P: Pointer<T>>(&self, new: P, ord: Ordering) {
self.data.store(new.into_usize(), ord);
}

Expand Down Expand Up @@ -1056,7 +1055,7 @@ impl<'g, T> Shared<'g, T> {
/// ```
pub unsafe fn into_owned(self) -> Owned<T> {
debug_assert!(
self.as_raw() != ptr::null(),
!self.as_raw().is_null(),
"converting a null `Shared` into `Owned`"
);
Owned::from_usize(self.data)
Expand Down
12 changes: 9 additions & 3 deletions crossbeam-epoch/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ pub struct Collector {
unsafe impl Send for Collector {}
unsafe impl Sync for Collector {}

impl Default for Collector {
fn default() -> Self {
Self {
global: Arc::new(Global::new()),
}
}
}

impl Collector {
/// Creates a new collector.
pub fn new() -> Self {
Collector {
global: Arc::new(Global::new()),
}
Self::default()
}

/// Registers a new handle for the collector.
Expand Down
3 changes: 3 additions & 0 deletions crossbeam-epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]
#![cfg_attr(feature = "nightly", feature(const_fn))]
// TODO(@jeehoonkang): needs to be removed
#![allow(clippy::missing_safety_doc)]

use cfg_if::cfg_if;

Expand Down
1 change: 1 addition & 0 deletions crossbeam-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nightly = []
[dependencies]
cfg-if = "0.1.10"
lazy_static = { version = "1.1.0", optional = true }
arr_macro = "0.1.3"

[build-dependencies]
autocfg = "1"
Expand Down
11 changes: 3 additions & 8 deletions crossbeam-utils/src/atomic/atomic_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use core::mem;
use core::ptr;
use core::sync::atomic::{self, AtomicBool, Ordering};

use arr_macro::arr;

#[cfg(feature = "std")]
use std::panic::{RefUnwindSafe, UnwindSafe};

Expand Down Expand Up @@ -638,14 +640,7 @@ fn lock(addr: usize) -> &'static SeqLock {
// In order to protect from such cases, we simply choose a large prime number for `LEN`.
const LEN: usize = 97;

const L: SeqLock = SeqLock::INIT;

static LOCKS: [SeqLock; 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,
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,
];
static LOCKS: [SeqLock; LEN] = arr![SeqLock::init(); 97];

// If the modulus is a constant number, the compiler will use crazy math to transform this into
// a sequence of cheap arithmetic operations rather than using the slow modulo instruction.
Expand Down
8 changes: 5 additions & 3 deletions crossbeam-utils/src/atomic/seq_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ pub struct SeqLock {
}

impl SeqLock {
pub const INIT: Self = Self {
state: AtomicUsize::new(0),
};
pub const fn init() -> Self {
Self {
state: AtomicUsize::new(0),
}
}

/// If not locked, returns the current stamp.
///
Expand Down
34 changes: 21 additions & 13 deletions crossbeam-utils/src/sync/parker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ pub struct Parker {

unsafe impl Send for Parker {}

impl Default for Parker {
fn default() -> Self {
Self {
unparker: Unparker {
inner: Arc::new(Inner {
state: AtomicUsize::new(EMPTY),
lock: Mutex::new(()),
cvar: Condvar::new(),
}),
},
_marker: PhantomData,
}
}
}

impl Parker {
/// Creates a new `Parker`.
///
Expand All @@ -70,16 +85,7 @@ impl Parker {
/// ```
///
pub fn new() -> Parker {
Parker {
unparker: Unparker {
inner: Arc::new(Inner {
state: AtomicUsize::new(EMPTY),
lock: Mutex::new(()),
cvar: Condvar::new(),
}),
},
_marker: PhantomData,
}
Self::default()
}

/// Blocks the current thread until the token is made available.
Expand Down Expand Up @@ -346,10 +352,12 @@ impl Inner {
// Block the current thread on the conditional variable.
m = self.cvar.wait(m).unwrap();

match self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst) {
Ok(_) => return, // got a notification
Err(_) => {} // spurious wakeup, go back to sleep
if self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst).is_ok() {
// got a notification
return;
}

// spurious wakeup, go back to sleep
}
}
Some(timeout) => {
Expand Down
20 changes: 13 additions & 7 deletions crossbeam-utils/src/sync/wait_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ struct Inner {
count: Mutex<usize>,
}

impl Default for WaitGroup {
fn default() -> Self {
Self {
inner: Arc::new(Inner {
cvar: Condvar::new(),
count: Mutex::new(1),
}),
}
}
}

impl WaitGroup {
/// Creates a new wait group and returns the single reference to it.
///
Expand All @@ -62,13 +73,8 @@ impl WaitGroup {
///
/// let wg = WaitGroup::new();
/// ```
pub fn new() -> WaitGroup {
WaitGroup {
inner: Arc::new(Inner {
cvar: Condvar::new(),
count: Mutex::new(1),
}),
}
pub fn new() -> Self {
Self::default()
}

/// Drops this reference and waits until all other references are dropped.
Expand Down
19 changes: 8 additions & 11 deletions crossbeam-utils/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,15 @@ where
wg.wait();

// Join all remaining spawned threads.
let panics: Vec<_> = {
let mut handles = scope.handles.lock().unwrap();

let panics: Vec<_> = scope
.handles
.lock()
.unwrap()
// Filter handles that haven't been joined, join them, and collect errors.
let panics = handles
.drain(..)
.filter_map(|handle| handle.lock().unwrap().take())
.filter_map(|handle| handle.join().err())
.collect();

panics
};
.drain(..)
.filter_map(|handle| handle.lock().unwrap().take())
.filter_map(|handle| handle.join().err())
.collect();

// If `f` has panicked, resume unwinding.
// If any of the child threads have panicked, return the panic errors.
Expand Down

0 comments on commit 1383018

Please sign in to comment.