mirror of
https://github.com/openharmony/third_party_rust_parking_lot.git
synced 2026-07-01 21:03:59 -04:00
Merge pull request #325 from taiki-e/const_fn_trait_bound
This commit is contained in:
@@ -91,9 +91,6 @@ lock.
|
||||
|
||||
There are a few restrictions when using this library on stable Rust:
|
||||
|
||||
- You will have to use the `const_*` functions (e.g. `const_mutex(val)`) to
|
||||
statically initialize the locking primitives. Using e.g. `Mutex::new(val)`
|
||||
does not work on stable Rust yet.
|
||||
- The `wasm32-unknown-unknown` target is only fully supported on nightly with
|
||||
`-C target-feature=+atomics` in `RUSTFLAGS` and `-Z build-std` passed to cargo.
|
||||
parking_lot will work mostly fine on stable, the only difference is it will
|
||||
|
||||
@@ -18,6 +18,9 @@ owning_ref = { version = "0.4.1", optional = true }
|
||||
# support, just pass "--features serde" when building this crate.
|
||||
serde = { version = "1.0.126", default-features = false, optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
autocfg = "1.1.0"
|
||||
|
||||
[features]
|
||||
nightly = []
|
||||
arc_lock = []
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
let cfg = autocfg::new();
|
||||
|
||||
if cfg.probe_rustc_version(1, 61) {
|
||||
println!("cargo:rustc-cfg=has_const_fn_trait_bound");
|
||||
}
|
||||
}
|
||||
@@ -84,13 +84,10 @@
|
||||
//! - `owning_ref`: Allows your lock types to be used with the `owning_ref` crate.
|
||||
//! - `arc_lock`: Enables locking from an `Arc`. This enables types such as `ArcMutexGuard`. Note that this
|
||||
//! requires the `alloc` crate to be present.
|
||||
//! - `nightly`: Enables nightly-only features. At the moment the only such
|
||||
//! feature is `const fn` constructors for lock types.
|
||||
|
||||
#![no_std]
|
||||
#![warn(missing_docs)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg_attr(feature = "nightly", feature(const_fn_trait_bound))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate scopeguard;
|
||||
|
||||
@@ -149,7 +149,7 @@ unsafe impl<R: RawMutex + Sync, T: ?Sized + Send> Sync for Mutex<R, T> {}
|
||||
|
||||
impl<R: RawMutex, T> Mutex<R, T> {
|
||||
/// Creates a new mutex in an unlocked state ready for use.
|
||||
#[cfg(feature = "nightly")]
|
||||
#[cfg(has_const_fn_trait_bound)]
|
||||
#[inline]
|
||||
pub const fn new(val: T) -> Mutex<R, T> {
|
||||
Mutex {
|
||||
@@ -159,7 +159,7 @@ impl<R: RawMutex, T> Mutex<R, T> {
|
||||
}
|
||||
|
||||
/// Creates a new mutex in an unlocked state ready for use.
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
#[cfg(not(has_const_fn_trait_bound))]
|
||||
#[inline]
|
||||
pub fn new(val: T) -> Mutex<R, T> {
|
||||
Mutex {
|
||||
|
||||
@@ -230,7 +230,7 @@ unsafe impl<R: RawMutex + Sync, G: GetThreadId + Sync, T: ?Sized + Send> Sync
|
||||
|
||||
impl<R: RawMutex, G: GetThreadId, T> ReentrantMutex<R, G, T> {
|
||||
/// Creates a new reentrant mutex in an unlocked state ready for use.
|
||||
#[cfg(feature = "nightly")]
|
||||
#[cfg(has_const_fn_trait_bound)]
|
||||
#[inline]
|
||||
pub const fn new(val: T) -> ReentrantMutex<R, G, T> {
|
||||
ReentrantMutex {
|
||||
@@ -245,7 +245,7 @@ impl<R: RawMutex, G: GetThreadId, T> ReentrantMutex<R, G, T> {
|
||||
}
|
||||
|
||||
/// Creates a new reentrant mutex in an unlocked state ready for use.
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
#[cfg(not(has_const_fn_trait_bound))]
|
||||
#[inline]
|
||||
pub fn new(val: T) -> ReentrantMutex<R, G, T> {
|
||||
ReentrantMutex {
|
||||
|
||||
@@ -366,7 +366,7 @@ unsafe impl<R: RawRwLock + Sync, T: ?Sized + Send + Sync> Sync for RwLock<R, T>
|
||||
|
||||
impl<R: RawRwLock, T> RwLock<R, T> {
|
||||
/// Creates a new instance of an `RwLock<T>` which is unlocked.
|
||||
#[cfg(feature = "nightly")]
|
||||
#[cfg(has_const_fn_trait_bound)]
|
||||
#[inline]
|
||||
pub const fn new(val: T) -> RwLock<R, T> {
|
||||
RwLock {
|
||||
@@ -376,7 +376,7 @@ impl<R: RawRwLock, T> RwLock<R, T> {
|
||||
}
|
||||
|
||||
/// Creates a new instance of an `RwLock<T>` which is unlocked.
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
#[cfg(not(has_const_fn_trait_bound))]
|
||||
#[inline]
|
||||
pub fn new(val: T) -> RwLock<R, T> {
|
||||
RwLock {
|
||||
@@ -892,7 +892,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
|
||||
/// Attempts to lock this `RwLock` with shared read access, through an `Arc`.
|
||||
///
|
||||
/// This method is similar to the `try_read_recursive` method; however, it requires the `RwLock` to be inside
|
||||
/// of an `Arc` and the resulting read guard has no lifetime requirements.
|
||||
/// of an `Arc` and the resulting read guard has no lifetime requirements.
|
||||
#[cfg(feature = "arc_lock")]
|
||||
#[inline]
|
||||
pub fn try_read_recursive_arc(self: &Arc<Self>) -> Option<ArcRwLockReadGuard<R, T>> {
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ impl WaitTimeoutResult {
|
||||
/// woken up.
|
||||
/// - Only requires 1 word of space, whereas the standard library boxes the
|
||||
/// `Condvar` due to platform limitations.
|
||||
/// - Can be statically constructed (requires the `const_fn` nightly feature).
|
||||
/// - Can be statically constructed.
|
||||
/// - Does not require any drop glue when dropped.
|
||||
/// - Inline fast path for the uncontended case.
|
||||
///
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ use lock_api;
|
||||
/// - No poisoning, the lock is released normally on panic.
|
||||
/// - Only requires 1 byte of space, whereas the standard library boxes the
|
||||
/// `FairMutex` due to platform limitations.
|
||||
/// - Can be statically constructed (requires the `const_fn` nightly feature).
|
||||
/// - Can be statically constructed.
|
||||
/// - Does not require any drop glue when dropped.
|
||||
/// - Inline fast path for the uncontended case.
|
||||
/// - Efficient handling of micro-contention using adaptive spinning.
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ use lock_api;
|
||||
/// - No poisoning, the lock is released normally on panic.
|
||||
/// - Only requires 1 byte of space, whereas the standard library boxes the
|
||||
/// `Mutex` due to platform limitations.
|
||||
/// - Can be statically constructed (requires the `const_fn` nightly feature).
|
||||
/// - Can be statically constructed.
|
||||
/// - Does not require any drop glue when dropped.
|
||||
/// - Inline fast path for the uncontended case.
|
||||
/// - Efficient handling of micro-contention using adaptive spinning.
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ use lock_api;
|
||||
/// - No poisoning, the lock is released normally on panic.
|
||||
/// - Only requires 1 word of space, whereas the standard library boxes the
|
||||
/// `RwLock` due to platform limitations.
|
||||
/// - Can be statically constructed (requires the `const_fn` nightly feature).
|
||||
/// - Can be statically constructed.
|
||||
/// - Does not require any drop glue when dropped.
|
||||
/// - Inline fast path for the uncontended case.
|
||||
/// - Efficient handling of micro-contention using adaptive spinning.
|
||||
|
||||
Reference in New Issue
Block a user