Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ features = ["macros", "extension-module"]
[dependencies.cfg-if]
version = "1.0.3"

[dependencies.parking_lot_core]
version = "0.9.11"
default-features = false
[dependencies.parking_lot]
version = "0.12.4"

[dependencies.lock_api]
version = "0.4.13"
Expand Down
8 changes: 4 additions & 4 deletions src/bridge/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::common::PreHashObject;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct Cache {
raw: crate::mutex::Mutex<crate::policies::nopolicy::NoPolicy>,
raw: crate::common::Mutex<crate::policies::nopolicy::NoPolicy>,
}

#[allow(non_camel_case_types)]
#[pyo3::pyclass(module = "cachebox._core")]
pub struct cache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<hashbrown::raw::RawIter<(PreHashObject, pyo3::Py<pyo3::PyAny>)>>,
pub iter: crate::common::Mutex<hashbrown::raw::RawIter<(PreHashObject, pyo3::Py<pyo3::PyAny>)>>,
}

#[pyo3::pymethods]
Expand All @@ -22,7 +22,7 @@ impl Cache {
let raw = crate::policies::nopolicy::NoPolicy::new(maxsize, capacity)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Cache {

let result = cache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
};

pyo3::Py::new(slf.py(), result)
Expand Down
8 changes: 4 additions & 4 deletions src/bridge/fifocache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::common::PreHashObject;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct FIFOCache {
raw: crate::mutex::Mutex<crate::policies::fifo::FIFOPolicy>,
raw: crate::common::Mutex<crate::policies::fifo::FIFOPolicy>,
}

#[allow(non_camel_case_types)]
#[pyo3::pyclass(module = "cachebox._core")]
pub struct fifocache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<crate::policies::fifo::FIFOIterator>,
pub iter: crate::common::Mutex<crate::policies::fifo::FIFOIterator>,
}

#[pyo3::pymethods]
Expand All @@ -22,7 +22,7 @@ impl FIFOCache {
let raw = crate::policies::fifo::FIFOPolicy::new(maxsize, capacity)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ impl FIFOCache {

let result = fifocache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
};

pyo3::Py::new(slf.py(), result)
Expand Down
8 changes: 4 additions & 4 deletions src/bridge/lfucache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::common::PreHashObject;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct LFUCache {
raw: crate::mutex::Mutex<crate::policies::lfu::LFUPolicy>,
raw: crate::common::Mutex<crate::policies::lfu::LFUPolicy>,
}

#[allow(non_camel_case_types)]
#[pyo3::pyclass(module = "cachebox._core")]
pub struct lfucache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<crate::policies::lfu::LFUIterator>,
pub iter: crate::common::Mutex<crate::policies::lfu::LFUIterator>,
}

#[pyo3::pymethods]
Expand All @@ -22,7 +22,7 @@ impl LFUCache {
let raw = crate::policies::lfu::LFUPolicy::new(maxsize, capacity)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ impl LFUCache {

let result = lfucache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
};

pyo3::Py::new(slf.py(), result)
Expand Down
8 changes: 4 additions & 4 deletions src/bridge/lrucache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::common::PreHashObject;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct LRUCache {
raw: crate::mutex::Mutex<crate::policies::lru::LRUPolicy>,
raw: crate::common::Mutex<crate::policies::lru::LRUPolicy>,
}

#[allow(non_camel_case_types)]
#[pyo3::pyclass(module = "cachebox._core")]
pub struct lrucache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<crate::linked_list::Iter>,
pub iter: crate::common::Mutex<crate::linked_list::Iter>,
}

#[pyo3::pymethods]
Expand All @@ -22,7 +22,7 @@ impl LRUCache {
let raw = crate::policies::lru::LRUPolicy::new(maxsize, capacity)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -230,7 +230,7 @@ impl LRUCache {

let result = lrucache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
};

pyo3::Py::new(slf.py(), result)
Expand Down
6 changes: 3 additions & 3 deletions src/bridge/rrcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::common::PreHashObject;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct RRCache {
raw: crate::mutex::Mutex<crate::policies::random::RandomPolicy>,
raw: crate::common::Mutex<crate::policies::random::RandomPolicy>,
}

#[pyo3::pymethods]
Expand All @@ -16,7 +16,7 @@ impl RRCache {
let raw = crate::policies::random::RandomPolicy::new(maxsize, capacity)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ impl RRCache {

let result = cache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
};

pyo3::Py::new(slf.py(), result)
Expand Down
8 changes: 4 additions & 4 deletions src/bridge/ttlcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use crate::common::TimeToLivePair;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct TTLCache {
raw: crate::mutex::Mutex<crate::policies::ttl::TTLPolicy>,
raw: crate::common::Mutex<crate::policies::ttl::TTLPolicy>,
}

#[allow(non_camel_case_types)]
#[pyo3::pyclass(module = "cachebox._core")]
pub struct ttlcache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<crate::policies::ttl::TTLIterator>,
pub iter: crate::common::Mutex<crate::policies::ttl::TTLIterator>,
pub now: std::time::SystemTime,
}

Expand All @@ -24,7 +24,7 @@ impl TTLCache {
let raw = crate::policies::ttl::TTLPolicy::new(maxsize, capacity, ttl)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ impl TTLCache {

let result = ttlcache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
now: std::time::SystemTime::now(),
};

Expand Down
8 changes: 4 additions & 4 deletions src/bridge/vttlcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use crate::common::TimeToLivePair;

#[pyo3::pyclass(module = "cachebox._core", frozen)]
pub struct VTTLCache {
raw: crate::mutex::Mutex<crate::policies::vttl::VTTLPolicy>,
raw: crate::common::Mutex<crate::policies::vttl::VTTLPolicy>,
}

#[allow(non_camel_case_types)]
#[pyo3::pyclass(module = "cachebox._core")]
pub struct vttlcache_items {
pub ptr: ObservedIterator,
pub iter: crate::mutex::Mutex<crate::policies::vttl::VTTLIterator>,
pub iter: crate::common::Mutex<crate::policies::vttl::VTTLIterator>,
pub now: std::time::SystemTime,
}

Expand All @@ -24,7 +24,7 @@ impl VTTLCache {
let raw = crate::policies::vttl::VTTLPolicy::new(maxsize, capacity)?;

let self_ = Self {
raw: crate::mutex::Mutex::new(raw),
raw: crate::common::Mutex::new(raw),
};
Ok(self_)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ impl VTTLCache {

let result = vttlcache_items {
ptr: ObservedIterator::new(slf.as_ptr(), state),
iter: crate::mutex::Mutex::new(iter),
iter: crate::common::Mutex::new(iter),
now: std::time::SystemTime::now(),
};

Expand Down
4 changes: 4 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,7 @@ impl TimeToLivePair {
}
}
}

// Thanks to `Amanieu d'Antras` for this beautiful implementation.
// https://github.com/Amanieu/parking_lot/blob/eeb186c48c8e6433c10f7552ef1cd1d56e5c83b1/src/raw_mutex.rs
pub type Mutex<T> = lock_api::Mutex<parking_lot::RawMutex, T>;
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use pyo3::prelude::*;

mod lazyheap;
mod linked_list;
mod mutex;

#[macro_use]
mod common;
Expand Down
Loading