diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:59:12 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:59:12 +0000 |
commit | fed84fbeb9e18b9f156ff74f04d74152804e8779 (patch) | |
tree | a0f94fee8e768791c965b5939f1d3c66f8e46a79 | |
parent | 6738440dc40dae197d3f4208607dbefbbd722cc6 (diff) | |
parent | 12f68c351f6540352b8bbe53b468172980d31828 (diff) | |
download | lock_api-android14-mainline-extservices-release.tar.gz |
Snap for 10453563 from 12f68c351f6540352b8bbe53b468172980d31828 to mainline-extservices-releaseaml_ext_341716000aml_ext_341620040aml_ext_341518010aml_ext_341414010aml_ext_341317010aml_ext_341131030aml_ext_341027030android14-mainline-extservices-release
Change-Id: I2d66f320ef8e33f8c0f44c70975be57295c27b4c
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 7 | ||||
-rw-r--r-- | Cargo.toml | 20 | ||||
-rw-r--r-- | Cargo.toml.orig | 7 | ||||
-rw-r--r-- | METADATA | 12 | ||||
-rw-r--r-- | build.rs | 7 | ||||
-rw-r--r-- | cargo2android.json | 2 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/mutex.rs | 44 | ||||
-rw-r--r-- | src/remutex.rs | 12 | ||||
-rw-r--r-- | src/rwlock.rs | 16 |
11 files changed, 96 insertions, 36 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 9ed45c2..6b5d531 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "a75875b0bf904287a9749e8eabea919b5e9dd8a9" + "sha1": "9e956adc2c6ecde7c15ff7611396d24be711c8a9" }, "path_in_vcs": "lock_api" }
\ No newline at end of file @@ -42,16 +42,19 @@ rust_library { host_supported: true, crate_name: "lock_api", cargo_env_compat: true, - cargo_pkg_version: "0.4.6", + cargo_pkg_version: "0.4.9", srcs: ["src/lib.rs"], edition: "2018", + cfgs: ["has_const_fn_trait_bound"], rustlibs: [ "libscopeguard", ], apex_available: [ "//apex_available:platform", - "com.android.bluetooth", + "com.android.btservices", "com.android.virt", ], + product_available: true, + vendor_available: true, min_sdk_version: "29", } @@ -12,13 +12,22 @@ [package] edition = "2018" name = "lock_api" -version = "0.4.6" +version = "0.4.9" authors = ["Amanieu d'Antras <amanieu@gmail.com>"] description = "Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std." -keywords = ["mutex", "rwlock", "lock", "no_std"] -categories = ["concurrency", "no-std"] -license = "Apache-2.0/MIT" +keywords = [ + "mutex", + "rwlock", + "lock", + "no_std", +] +categories = [ + "concurrency", + "no-std", +] +license = "MIT OR Apache-2.0" repository = "https://github.com/Amanieu/parking_lot" + [dependencies.owning_ref] version = "0.4.1" optional = true @@ -32,6 +41,9 @@ version = "1.0.126" optional = true default-features = false +[build-dependencies.autocfg] +version = "1.1.0" + [features] arc_lock = [] nightly = [] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index e6a805f..c21bd8a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,9 +1,9 @@ [package] name = "lock_api" -version = "0.4.6" +version = "0.4.9" authors = ["Amanieu d'Antras <amanieu@gmail.com>"] description = "Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std." -license = "Apache-2.0/MIT" +license = "MIT OR Apache-2.0" repository = "https://github.com/Amanieu/parking_lot" keywords = ["mutex", "rwlock", "lock", "no_std"] categories = ["concurrency", "no-std"] @@ -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 = [] @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/lock_api +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "lock_api" description: "Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std." third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/lock_api/lock_api-0.4.6.crate" + value: "https://static.crates.io/crates/lock_api/lock_api-0.4.9.crate" } - version: "0.4.6" + version: "0.4.9" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 1 + month: 12 + day: 12 } } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..886a345 --- /dev/null +++ b/build.rs @@ -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"); + } +} diff --git a/cargo2android.json b/cargo2android.json index 22531ba..da746ae 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,7 +1,7 @@ { "apex-available": [ "//apex_available:platform", - "com.android.bluetooth", + "com.android.btservices", "com.android.virt" ], "device": true, @@ -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; diff --git a/src/mutex.rs b/src/mutex.rs index 81c25fb..c97e543 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -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 { @@ -565,6 +565,17 @@ impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T> { defer!(s.mutex.raw.lock()); f() } + + /// Leaks the mutex guard and returns a mutable reference to the data + /// protected by the mutex. + /// + /// This will leave the `Mutex` in a locked state. + #[inline] + pub fn leak(s: Self) -> &'a mut T { + let r = unsafe { &mut *s.mutex.data.get() }; + mem::forget(s); + r + } } impl<'a, R: RawMutexFair + 'a, T: ?Sized + 'a> MutexGuard<'a, R, T> { @@ -670,15 +681,38 @@ unsafe impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> StableAddress for MutexGuard<' #[must_use = "if unused the Mutex will immediately unlock"] pub struct ArcMutexGuard<R: RawMutex, T: ?Sized> { mutex: Arc<Mutex<R, T>>, - marker: PhantomData<R::GuardMarker>, + marker: PhantomData<*const ()>, +} + +#[cfg(feature = "arc_lock")] +unsafe impl<R: RawMutex + Send + Sync, T: Send + ?Sized> Send for ArcMutexGuard<R, T> where + R::GuardMarker: Send +{ +} +#[cfg(feature = "arc_lock")] +unsafe impl<R: RawMutex + Sync, T: Sync + ?Sized> Sync for ArcMutexGuard<R, T> where + R::GuardMarker: Sync +{ } #[cfg(feature = "arc_lock")] impl<R: RawMutex, T: ?Sized> ArcMutexGuard<R, T> { /// Returns a reference to the `Mutex` this is guarding, contained in its `Arc`. #[inline] - pub fn mutex(&self) -> &Arc<Mutex<R, T>> { - &self.mutex + pub fn mutex(s: &Self) -> &Arc<Mutex<R, T>> { + &s.mutex + } + + /// Unlocks the mutex and returns the `Arc` that was held by the [`ArcMutexGuard`]. + #[inline] + pub fn into_arc(s: Self) -> Arc<Mutex<R, T>> { + // Safety: Skip our Drop impl and manually unlock the mutex. + let arc = unsafe { ptr::read(&s.mutex) }; + mem::forget(s); + unsafe { + arc.raw.unlock(); + } + arc } /// Temporarily unlocks the mutex to execute the given function. diff --git a/src/remutex.rs b/src/remutex.rs index dd992b4..3e2010f 100644 --- a/src/remutex.rs +++ b/src/remutex.rs @@ -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 { @@ -646,7 +646,7 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGu /// in already locked the mutex. /// /// This is an associated function that needs to be - /// used as `ReentrantMutexGuard::map(...)`. A method would interfere with methods of + /// used as `ReentrantMutexGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>( @@ -654,10 +654,10 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGu f: F, ) -> Result<MappedReentrantMutexGuard<'a, R, G, U>, Self> where - F: FnOnce(&mut T) -> Option<&mut U>, + F: FnOnce(&T) -> Option<&U>, { let raw = &s.remutex.raw; - let data = match f(unsafe { &mut *s.remutex.data.get() }) { + let data = match f(unsafe { &*s.remutex.data.get() }) { Some(data) => data, None => return Err(s), }; @@ -942,7 +942,7 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> /// in already locked the mutex. /// /// This is an associated function that needs to be - /// used as `MappedReentrantMutexGuard::map(...)`. A method would interfere with methods of + /// used as `MappedReentrantMutexGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>( diff --git a/src/rwlock.rs b/src/rwlock.rs index 9bfa1da..c972fb6 100644 --- a/src/rwlock.rs +++ b/src/rwlock.rs @@ -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>> { @@ -1218,13 +1218,13 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> RwLockReadGuard<'a, R, T> { } /// Attempts to make a new `MappedRwLockReadGuard` for a component of the - /// locked data. The original guard is return if the closure returns `None`. + /// locked data. Returns the original guard if the closure returns `None`. /// /// This operation cannot fail as the `RwLockReadGuard` passed /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `RwLockReadGuard::map(...)`. A method would interfere with methods of + /// used as `RwLockReadGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockReadGuard<'a, R, U>, Self> @@ -1512,7 +1512,7 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> RwLockWriteGuard<'a, R, T> { /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `RwLockWriteGuard::map(...)`. A method would interfere with methods of + /// used as `RwLockWriteGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, R, U>, Self> @@ -2374,7 +2374,7 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> MappedRwLockReadGuard<'a, R, T> { /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `MappedRwLockReadGuard::map(...)`. A method would interfere with methods of + /// used as `MappedRwLockReadGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockReadGuard<'a, R, U>, Self> @@ -2512,7 +2512,7 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> MappedRwLockWriteGuard<'a, R, T> { /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `MappedRwLockWriteGuard::map(...)`. A method would interfere with methods of + /// used as `MappedRwLockWriteGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, R, U>, Self> |