remove no_std for now

This commit is contained in:
Acrimon 2020-12-26 00:30:17 +01:00
parent f167aec2b4
commit 978ffb5f0f
No known key found for this signature in database
GPG Key ID: FE567F46AFBDF3AE
7 changed files with 9 additions and 78 deletions

View File

@ -15,13 +15,11 @@ categories = ["concurrency", "algorithms", "data-structures"]
[features]
default = []
raw-api = []
no_std = ["hashbrown"]
[dependencies]
num_cpus = "1.13.0"
serde = { version = "1.0.118", optional = true, features = ["derive"] }
cfg-if = "1.0.0"
hashbrown = { version = "0.9.1", optional = true }
rayon = { version = "1.5.0", optional = true }
[package.metadata.docs.rs]

View File

@ -24,12 +24,12 @@ If you have any suggestions or tips do not hesitate to open an issue or a PR.
## Cargo features
- `no_std` - Enable no_std + alloc support.
- `serde` - Enables serde support.
- `raw-api` - Enables the unstable raw-shard api.
- `rayon` - Enables rayon support.
## Support me
[![Foo](https://c5.patreon.com/external/logo/become_a_patron_button@2x.png)](https://patreon.com/acrimon)

View File

@ -6,17 +6,9 @@ use crate::util::SharedValue;
use crate::{DashMap, HashMap};
use core::hash::{BuildHasher, Hash};
use core::mem;
use std::collections::hash_map;
use std::collections::hash_map::RandomState;
cfg_if::cfg_if! {
if #[cfg(feature = "no_std")] {
use alloc::sync::Arc;
use hashbrown::hash_map;
} else {
use std::sync::Arc;
use std::collections::hash_map;
}
}
use std::sync::Arc;
/// Iterator over a DashMap yielding key value pairs.
///

View File

@ -1,4 +1,3 @@
#![cfg_attr(all(feature = "no_std", not(test)), no_std)] // Note: Concurrency tests require std for threading/channels
#![allow(clippy::type_complexity)]
pub mod iter;
@ -43,17 +42,7 @@ cfg_if! {
}
}
cfg_if! {
if #[cfg(feature = "no_std")] {
extern crate alloc;
use alloc::{vec::Vec, boxed::Box};
pub(crate) type HashMap<K, V, S> = hashbrown::HashMap<K, SharedValue<V>, S>;
} else {
pub(crate) type HashMap<K, V, S> = std::collections::HashMap<K, SharedValue<V>, S>;
}
}
pub(crate) type HashMap<K, V, S> = std::collections::HashMap<K, SharedValue<V>, S>;
fn shard_amount() -> usize {
(num_cpus::get() * 4).next_power_of_two()

View File

@ -4,14 +4,7 @@ use core::hash::BuildHasher;
use core::hash::Hash;
use core::ops::{Deref, DerefMut};
use std::collections::hash_map::RandomState;
cfg_if::cfg_if! {
if #[cfg(feature = "no_std")] {
use alloc::sync::Arc;
} else {
use std::sync::Arc;
}
}
use std::sync::Arc;
// -- Shared
pub struct RefMulti<'a, K, V, S = RandomState> {

View File

@ -6,14 +6,7 @@ use core::hash::{BuildHasher, Hash};
use rayon::iter::plumbing::UnindexedConsumer;
use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator};
use std::collections::hash_map::RandomState;
cfg_if::cfg_if! {
if #[cfg(feature = "no_std")] {
use alloc::{boxed::Box, sync::Arc, vec::Vec};
} else {
use std::sync::Arc;
}
}
use std::sync::Arc;
impl<K, V, S> ParallelExtend<(K, V)> for DashMap<K, V, S>
where

View File

@ -95,42 +95,8 @@ struct AbortOnPanic;
impl Drop for AbortOnPanic {
fn drop(&mut self) {
cfg_if::cfg_if! {
if #[cfg(feature = "no_std")] {
// Note: This is hard, as core/no_std has no concept of threads or knowledge of panicking.
// An alternative would be to do this:
//
// ```rust
// // Elsewhere in the library/host binary
// use core::sync::atomic::{AtomicBool, Ordering};
//
// static UNWINDING: AtomicBool = AtomicBool::new(false);
//
// #[panic_handler]
// fn panic(info: &PanicInfo) -> ! {
// UNWINDING.store(true, Ordering::Relaxed);
//
// unsafe {
// core::intrinsics::abort();
// }
// }
//
// // In AbortOnPanic::drop
// if UNWINDING.load(Ordering::Relaxed) {
// unsafe {
// core::intrinsics::abort();
// }
// }
// ```
//
// Now, this isn't an ideal solution for multiple reasons, as it uses intrinsics which require a feature
// and can be overwritten by the user without them even knowing. That being said, *most* users of no_std
// do tend to use panic = "abort", which solves this problem for us by aborting on panics.
} else {
if std::thread::panicking() {
std::process::abort()
}
}
if std::thread::panicking() {
std::process::abort()
}
}
}