Skip to content

Commit

Permalink
Construct owned Collector in no_std
Browse files Browse the repository at this point in the history
On `no_std`, users are forced to use `HashMap::guard` anyway, since
`epoch::pin` isn't available, so this seems fine.
  • Loading branch information
jonhoo committed Feb 1, 2020
1 parent a8a7ae3 commit 28d66a3
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use crate::iter::*;
use crate::node::*;
use crate::raw::*;
use core::borrow::Borrow;
use core::fmt::{self, Debug, Formatter};
use core::hash::{BuildHasher, Hash, Hasher};
#[cfg(feature = "std")]
use core::iter::FromIterator;
use core::sync::atomic::{AtomicIsize, AtomicUsize, Ordering};
use crossbeam_epoch::{self as epoch, Atomic, Guard, Owned, Shared};
#[cfg(feature = "std")]
use std::fmt::{self, Debug, Formatter};
#[cfg(feature = "std")]
use std::sync::Once;

const ISIZE_BITS: usize = core::mem::size_of::<isize>() * 8;
Expand Down Expand Up @@ -161,7 +159,6 @@ fn disallow_evil() {
assert_eq!(oops.unwrap(), "hello");
}

#[cfg(feature = "std")]
impl<K, V, L, S> Default for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Hash + Eq,
Expand All @@ -174,7 +171,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, L> ConcurrentHashMap<K, V, L, crate::DefaultHashBuilder>
where
K: Sync + Send + Clone + Hash + Eq,
Expand All @@ -200,7 +196,6 @@ where
L: lock_api::RawMutex,
S: BuildHasher,
{
#[cfg(feature = "std")]
/// Creates an empty map which will use `hash_builder` to hash keys.
///
/// The created map has the default initial capacity.
Expand All @@ -217,7 +212,10 @@ where
count: AtomicUsize::new(0),
size_ctl: AtomicIsize::new(0),
build_hasher: hash_builder,
#[cfg(feature = "std")]
collector: epoch::default_collector().clone(),
#[cfg(not(feature = "std"))]
collector: epoch::Collector::new(),
}
}

Expand Down Expand Up @@ -264,7 +262,6 @@ where
}
}

#[cfg(feature = "std")]
/// Creates an empty map with the specified `capacity`, using `hash_builder` to hash the keys.
///
/// The map will be sized to accommodate `capacity` elements with a low chance of reallocating
Expand Down Expand Up @@ -756,7 +753,6 @@ where
}
}

#[cfg_attr(not(feature = "std"), allow(dead_code))]
fn put_all<I: Iterator<Item = (K, V)>>(&self, iter: I, guard: &Guard) {
for (key, value) in iter {
self.put(key, value, false, guard);
Expand Down Expand Up @@ -1802,7 +1798,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, L, S> PartialEq for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Eq + Hash,
Expand All @@ -1818,7 +1813,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, L, S> Eq for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Eq + Hash,
Expand All @@ -1828,7 +1822,6 @@ where
{
}

#[cfg(feature = "std")]
impl<K, V, L, S> fmt::Debug for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Debug + Eq + Hash,
Expand All @@ -1837,7 +1830,7 @@ where
L: lock_api::RawMutex,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let guard = self.collector.register().pin();
let guard = self.guard();
f.debug_map().entries(self.iter(&guard)).finish()
}
}
Expand Down Expand Up @@ -1870,7 +1863,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, L, S> Extend<(K, V)> for &ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Hash + Eq,
Expand Down Expand Up @@ -1898,7 +1890,6 @@ where
}
}

#[cfg(feature = "std")]
impl<'a, K, V, L, S> Extend<(&'a K, &'a V)> for &ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Copy + Hash + Eq,
Expand All @@ -1912,7 +1903,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, L, S> FromIterator<(K, V)> for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Hash + Eq,
Expand Down Expand Up @@ -1941,7 +1931,6 @@ where
}
}

#[cfg(feature = "std")]
impl<'a, K, V, L, S> FromIterator<(&'a K, &'a V)> for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Copy + Hash + Eq,
Expand All @@ -1955,7 +1944,6 @@ where
}
}

#[cfg(feature = "std")]
impl<'a, K, V, L, S> FromIterator<&'a (K, V)> for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Copy + Hash + Eq,
Expand All @@ -1969,7 +1957,6 @@ where
}
}

#[cfg(feature = "std")]
impl<K, V, L, S> Clone for ConcurrentHashMap<K, V, L, S>
where
K: Sync + Send + Clone + Hash + Eq,
Expand Down

0 comments on commit 28d66a3

Please sign in to comment.