Skip to content

Commit

Permalink
Replace parking_lot with std::sync types
Browse files Browse the repository at this point in the history
As of rust-lang/rust#95035, the locking API
provided by std::sync is improved on Linux, outperforming parking_lot in
various cases. Using the built-in locking APIs means we can remove
parking_lot as a dependency, along with its own (indirect) dependencies;
removing a total of 10 dependencies.
  • Loading branch information
yorickpeterse committed Aug 20, 2022
1 parent a49c7fb commit 7004669
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 128 deletions.
87 changes: 2 additions & 85 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ libffi-system = ["libffi/system"]

[dependencies]
num_cpus = "^1.13"
parking_lot = "^0.12"

# Newer versions of the `time` crate only expose local time behind a
# compile-time --cfg flag. This isn't viable for us, as it makes the compilation
Expand Down
12 changes: 6 additions & 6 deletions vm/src/permanent_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::mem::{
};
use crate::process::Future;
use ahash::AHashMap;
use parking_lot::Mutex;
use std::mem::size_of;
use std::ops::Drop;
use std::sync::Mutex;

pub(crate) const INT_CLASS: usize = 0;
pub(crate) const FLOAT_CLASS: usize = 1;
Expand Down Expand Up @@ -169,7 +169,7 @@ impl PermanentSpace {
/// If an Inko String has already been allocated for the given Rust String,
/// the existing Inko String is returned; otherwise a new one is created.
pub(crate) fn allocate_string(&self, string: String) -> Pointer {
let mut strings = self.interned_strings.lock();
let mut strings = self.interned_strings.lock().unwrap();

if let Some(ptr) = strings.get(&string) {
return *ptr;
Expand All @@ -190,15 +190,15 @@ impl PermanentSpace {
} else {
let ptr = ptr.as_permanent();

self.permanent_objects.lock().push(ptr);
self.permanent_objects.lock().unwrap().push(ptr);
ptr
}
}

pub(crate) fn allocate_float(&self, value: f64) -> Pointer {
let ptr = Float::alloc(self.float_class(), value).as_permanent();

self.permanent_objects.lock().push(ptr);
self.permanent_objects.lock().unwrap().push(ptr);
ptr
}

Expand Down Expand Up @@ -290,11 +290,11 @@ impl PermanentSpace {
impl Drop for PermanentSpace {
fn drop(&mut self) {
unsafe {
for pointer in self.interned_strings.lock().values() {
for pointer in self.interned_strings.lock().unwrap().values() {
InkoString::drop_and_deallocate(*pointer);
}

for ptr in self.permanent_objects.lock().iter() {
for ptr in self.permanent_objects.lock().unwrap().iter() {
ptr.free();
}

Expand Down
Loading

0 comments on commit 7004669

Please sign in to comment.