-
Notifications
You must be signed in to change notification settings - Fork 13
Use #![no_std] by default #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vtta
wants to merge
2
commits into
robclu:main
Choose a base branch
from
vtta:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,15 +16,17 @@ use core::{ | |
| sync::atomic::{AtomicBool, AtomicPtr, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering}, | ||
| }; | ||
|
|
||
| use alloc::{vec, vec::Vec}; | ||
|
|
||
| #[cfg(not(feature = "stable_alloc"))] | ||
| use alloc::alloc::Global; | ||
| #[cfg(feature = "stable_alloc")] | ||
| use allocator_api2::alloc::{Allocator, Global}; | ||
| #[cfg(not(feature = "stable_alloc"))] | ||
| use core::alloc::Allocator; | ||
| #[cfg(not(feature = "stable_alloc"))] | ||
| use std::alloc::Global; | ||
|
|
||
| /// The default hasher for a [`LeapMap`]. | ||
| pub(crate) type DefaultHash = std::collections::hash_map::DefaultHasher; | ||
| pub(crate) type DefaultHash = crate::FnvHasher; | ||
|
|
||
| /// A concurrent hash map implementation which uses a modified form of RobinHood/ | ||
| /// Hopscotch probing. This implementation is lock-free, and therefore it will | ||
|
|
@@ -51,7 +53,7 @@ pub(crate) type DefaultHash = std::collections::hash_map::DefaultHasher; | |
| /// # Limitations | ||
| /// | ||
| /// This biggest limitations of this map are that the interface is slightly | ||
| /// different than using [`std::sync::RwLock<HashMap>`]. The type returned | ||
| /// different than using [`core::sync::RwLock<HashMap>`]. The type returned | ||
| /// when calling `get`, `get_mut`, `iter`, etc, are not references, but rather a | ||
| /// [`Ref`] or [`RefMut`] type which acts like a reference but still allows concurrent | ||
| /// operations on both that reference type and the map. This interface is still | ||
|
|
@@ -161,7 +163,8 @@ where | |
| A: Allocator, | ||
| { | ||
| /// The default initial size of the map. | ||
| const INITIAL_SIZE: usize = 8; | ||
| /// Make sure it's a multiple of CELLS_IN_USE, so that no floats are needed during resizing | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are -> are not
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, meant: "no floats are needed" -> "floats are not needed". It's a little more clear. |
||
| const INITIAL_SIZE: usize = Self::CELLS_IN_USE; | ||
|
|
||
| /// The max number of elements to search through when having to fallback | ||
| /// to using linear search to try to find a cell. | ||
|
|
@@ -747,9 +750,9 @@ where | |
| } | ||
|
|
||
| // Estimate how much we need to resize by: | ||
| let ratio = cells_in_use as f32 / Self::CELLS_IN_USE as f32; | ||
| let in_use_estimated = (size_mask + 1) as f32 * ratio; | ||
| let estimated = round_to_pow2((in_use_estimated * 2.0).max(1.0) as usize); | ||
| // Brute-froce estimate to avoid floats | ||
| let in_use_estimated = (size_mask + 1) * cells_in_use / Self::CELLS_IN_USE; | ||
| let estimated = round_to_pow2((in_use_estimated * 2) as usize); | ||
|
|
||
| // FIXME: This doesn't allow the map to shrink | ||
| //let new_table_size = estimated.max((size_mask + 1) as usize); | ||
|
|
@@ -975,7 +978,7 @@ where | |
| migrator.overflowed.store(false, Ordering::Relaxed); | ||
| //migrator | ||
| // .dst_table | ||
| // .store(std::ptr::null_mut(), Ordering::Relaxed); | ||
| // .store(core::ptr::null_mut(), Ordering::Relaxed); | ||
|
|
||
| // We don't move the source tables here, rather, we wait until the | ||
| // next mogration and add them to the cleanup queue then. | ||
|
|
@@ -1263,21 +1266,21 @@ where | |
| let bucket_count = cells >> 2; | ||
| let bucket_ptr = | ||
| allocate::<Bucket<K, V>, A>(allocator, bucket_count, AllocationKind::Uninitialized); | ||
| let buckets = unsafe { std::slice::from_raw_parts_mut(bucket_ptr, bucket_count) }; | ||
| let buckets = unsafe { core::slice::from_raw_parts_mut(bucket_ptr, bucket_count) }; | ||
|
|
||
| // Since AtomicU8 and AtomicU64 are the same as u8 and u64 in memory, | ||
| // we can write them as zero, rather than calling the atomic versions | ||
| for bucket in buckets.iter_mut().take(bucket_count) { | ||
| unsafe { | ||
| let bucket_deltas = &mut bucket.deltas as *mut AtomicU8; | ||
| std::ptr::write_bytes(bucket_deltas, 0, 8); | ||
| core::ptr::write_bytes(bucket_deltas, 0, 8); | ||
| }; | ||
|
|
||
| for cell in 0..4 { | ||
| unsafe { | ||
| // We only need to write the hash as null, an can ignore th key. | ||
| let cell_hash: *mut AtomicHashedKey = &mut bucket.cells[cell].hash; | ||
| std::ptr::write_bytes(cell_hash, 0, 1); | ||
| core::ptr::write_bytes(cell_hash, 0, 1); | ||
| }; | ||
|
|
||
| // FIXME: Check if the stored type is directly writable .. | ||
|
|
@@ -1476,12 +1479,12 @@ struct Table<K, V> { | |
| impl<K, V> Table<K, V> { | ||
| /// Gets a mutable slice of the table buckets. | ||
| pub(super) fn bucket_slice_mut(&mut self) -> &mut [Bucket<K, V>] { | ||
| unsafe { std::slice::from_raw_parts_mut(self.buckets, self.size()) } | ||
| unsafe { core::slice::from_raw_parts_mut(self.buckets, self.size()) } | ||
| } | ||
|
|
||
| /// Gets a slice of the table buckets. | ||
| pub(super) fn bucket_slice(&self) -> &[Bucket<K, V>] { | ||
| unsafe { std::slice::from_raw_parts(self.buckets, self.size()) } | ||
| unsafe { core::slice::from_raw_parts(self.buckets, self.size()) } | ||
| } | ||
|
|
||
| /// Returns the number of cells in the table. | ||
|
|
@@ -1589,11 +1592,11 @@ impl<K, V> Migrator<K, V> { | |
| self.stale_sources = Vec::with_capacity(Self::STALE_SOURCES); | ||
| for _ in 0..Self::STALE_SOURCES { | ||
| self.stale_sources | ||
| .push(AtomicPtr::<Table<K, V>>::new(std::ptr::null_mut())); | ||
| .push(AtomicPtr::<Table<K, V>>::new(core::ptr::null_mut())); | ||
| } | ||
|
|
||
| self.dst_table | ||
| .store(std::ptr::null_mut(), Ordering::Relaxed); | ||
| .store(core::ptr::null_mut(), Ordering::Relaxed); | ||
| self.sources = vec![]; | ||
| self.status.store(Self::RESET_FLAG, Ordering::Relaxed); | ||
| self.remaining_units.store(0, Ordering::Relaxed); | ||
|
|
@@ -1681,7 +1684,7 @@ impl<K, V> Migrator<K, V> { | |
| let bucket_count = table.size() >> 2; | ||
| deallocate::<Bucket<K, V>, A>(allocator, bucket_ptr, bucket_count); | ||
| deallocate::<Table<K, V>, A>(allocator, table_ptr, 1); | ||
| self.stale_sources[index].store(std::ptr::null_mut(), Ordering::Relaxed); | ||
| self.stale_sources[index].store(core::ptr::null_mut(), Ordering::Relaxed); | ||
| } | ||
|
|
||
| // Lost the race, just return. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are -> are not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, meant: "no floats are needed" -> "floats are not needed". It's a little more clear.