Skip to content

Commit 687efb8

Browse files
authored
Merge pull request #31 from chirizxc/clean-up
a bit clean up
2 parents 4002fa7 + 6a26e06 commit 687efb8

File tree

12 files changed

+44
-205
lines changed

12 files changed

+44
-205
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ features = ["macros", "extension-module"]
3737
[dependencies.cfg-if]
3838
version = "1.0.3"
3939

40-
[dependencies.parking_lot_core]
41-
version = "0.9.11"
42-
default-features = false
40+
[dependencies.parking_lot]
41+
version = "0.12.4"
4342

4443
[dependencies.lock_api]
4544
version = "0.4.13"

src/bridge/cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use crate::common::PreHashObject;
44

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

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

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

2424
let self_ = Self {
25-
raw: crate::mutex::Mutex::new(raw),
25+
raw: crate::common::Mutex::new(raw),
2626
};
2727
Ok(self_)
2828
}
@@ -205,7 +205,7 @@ impl Cache {
205205

206206
let result = cache_items {
207207
ptr: ObservedIterator::new(slf.as_ptr(), state),
208-
iter: crate::mutex::Mutex::new(iter),
208+
iter: crate::common::Mutex::new(iter),
209209
};
210210

211211
pyo3::Py::new(slf.py(), result)

src/bridge/fifocache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use crate::common::PreHashObject;
44

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

1010
#[allow(non_camel_case_types)]
1111
#[pyo3::pyclass(module = "cachebox._core")]
1212
pub struct fifocache_items {
1313
pub ptr: ObservedIterator,
14-
pub iter: crate::mutex::Mutex<crate::policies::fifo::FIFOIterator>,
14+
pub iter: crate::common::Mutex<crate::policies::fifo::FIFOIterator>,
1515
}
1616

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

2424
let self_ = Self {
25-
raw: crate::mutex::Mutex::new(raw),
25+
raw: crate::common::Mutex::new(raw),
2626
};
2727
Ok(self_)
2828
}
@@ -221,7 +221,7 @@ impl FIFOCache {
221221

222222
let result = fifocache_items {
223223
ptr: ObservedIterator::new(slf.as_ptr(), state),
224-
iter: crate::mutex::Mutex::new(iter),
224+
iter: crate::common::Mutex::new(iter),
225225
};
226226

227227
pyo3::Py::new(slf.py(), result)

src/bridge/lfucache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use crate::common::PreHashObject;
44

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

1010
#[allow(non_camel_case_types)]
1111
#[pyo3::pyclass(module = "cachebox._core")]
1212
pub struct lfucache_items {
1313
pub ptr: ObservedIterator,
14-
pub iter: crate::mutex::Mutex<crate::policies::lfu::LFUIterator>,
14+
pub iter: crate::common::Mutex<crate::policies::lfu::LFUIterator>,
1515
}
1616

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

2424
let self_ = Self {
25-
raw: crate::mutex::Mutex::new(raw),
25+
raw: crate::common::Mutex::new(raw),
2626
};
2727
Ok(self_)
2828
}
@@ -234,7 +234,7 @@ impl LFUCache {
234234

235235
let result = lfucache_items {
236236
ptr: ObservedIterator::new(slf.as_ptr(), state),
237-
iter: crate::mutex::Mutex::new(iter),
237+
iter: crate::common::Mutex::new(iter),
238238
};
239239

240240
pyo3::Py::new(slf.py(), result)

src/bridge/lrucache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use crate::common::PreHashObject;
44

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

1010
#[allow(non_camel_case_types)]
1111
#[pyo3::pyclass(module = "cachebox._core")]
1212
pub struct lrucache_items {
1313
pub ptr: ObservedIterator,
14-
pub iter: crate::mutex::Mutex<crate::linked_list::Iter>,
14+
pub iter: crate::common::Mutex<crate::linked_list::Iter>,
1515
}
1616

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

2424
let self_ = Self {
25-
raw: crate::mutex::Mutex::new(raw),
25+
raw: crate::common::Mutex::new(raw),
2626
};
2727
Ok(self_)
2828
}
@@ -230,7 +230,7 @@ impl LRUCache {
230230

231231
let result = lrucache_items {
232232
ptr: ObservedIterator::new(slf.as_ptr(), state),
233-
iter: crate::mutex::Mutex::new(iter),
233+
iter: crate::common::Mutex::new(iter),
234234
};
235235

236236
pyo3::Py::new(slf.py(), result)

src/bridge/rrcache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::common::PreHashObject;
55

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

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

1818
let self_ = Self {
19-
raw: crate::mutex::Mutex::new(raw),
19+
raw: crate::common::Mutex::new(raw),
2020
};
2121
Ok(self_)
2222
}
@@ -208,7 +208,7 @@ impl RRCache {
208208

209209
let result = cache_items {
210210
ptr: ObservedIterator::new(slf.as_ptr(), state),
211-
iter: crate::mutex::Mutex::new(iter),
211+
iter: crate::common::Mutex::new(iter),
212212
};
213213

214214
pyo3::Py::new(slf.py(), result)

src/bridge/ttlcache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::common::TimeToLivePair;
55

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

1111
#[allow(non_camel_case_types)]
1212
#[pyo3::pyclass(module = "cachebox._core")]
1313
pub struct ttlcache_items {
1414
pub ptr: ObservedIterator,
15-
pub iter: crate::mutex::Mutex<crate::policies::ttl::TTLIterator>,
15+
pub iter: crate::common::Mutex<crate::policies::ttl::TTLIterator>,
1616
pub now: std::time::SystemTime,
1717
}
1818

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

2626
let self_ = Self {
27-
raw: crate::mutex::Mutex::new(raw),
27+
raw: crate::common::Mutex::new(raw),
2828
};
2929
Ok(self_)
3030
}
@@ -224,7 +224,7 @@ impl TTLCache {
224224

225225
let result = ttlcache_items {
226226
ptr: ObservedIterator::new(slf.as_ptr(), state),
227-
iter: crate::mutex::Mutex::new(iter),
227+
iter: crate::common::Mutex::new(iter),
228228
now: std::time::SystemTime::now(),
229229
};
230230

src/bridge/vttlcache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::common::TimeToLivePair;
55

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

1111
#[allow(non_camel_case_types)]
1212
#[pyo3::pyclass(module = "cachebox._core")]
1313
pub struct vttlcache_items {
1414
pub ptr: ObservedIterator,
15-
pub iter: crate::mutex::Mutex<crate::policies::vttl::VTTLIterator>,
15+
pub iter: crate::common::Mutex<crate::policies::vttl::VTTLIterator>,
1616
pub now: std::time::SystemTime,
1717
}
1818

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

2626
let self_ = Self {
27-
raw: crate::mutex::Mutex::new(raw),
27+
raw: crate::common::Mutex::new(raw),
2828
};
2929
Ok(self_)
3030
}
@@ -224,7 +224,7 @@ impl VTTLCache {
224224

225225
let result = vttlcache_items {
226226
ptr: ObservedIterator::new(slf.as_ptr(), state),
227-
iter: crate::mutex::Mutex::new(iter),
227+
iter: crate::common::Mutex::new(iter),
228228
now: std::time::SystemTime::now(),
229229
};
230230

src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,7 @@ impl TimeToLivePair {
484484
}
485485
}
486486
}
487+
488+
// Thanks to `Amanieu d'Antras` for this beautiful implementation.
489+
// https://github.com/Amanieu/parking_lot/blob/eeb186c48c8e6433c10f7552ef1cd1d56e5c83b1/src/raw_mutex.rs
490+
pub type Mutex<T> = lock_api::Mutex<parking_lot::RawMutex, T>;

0 commit comments

Comments
 (0)