From 0460151a279148cbfbd2cbe8928fd1a3b1efe3d6 Mon Sep 17 00:00:00 2001 From: William Escande Date: Mon, 22 Aug 2022 11:27:59 -0700 Subject: [Bluetooth apex] Use new apex name The Bluetooth apex name is now called com.android.btservices Bug: 243054261 Test: Build Change-Id: I102c38853ac9d42ba16b6a105095d919a89e3a62 --- Android.bp | 2 +- cargo2android.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Android.bp b/Android.bp index 67d3a3b..35f09bc 100644 --- a/Android.bp +++ b/Android.bp @@ -50,7 +50,7 @@ rust_library { ], apex_available: [ "//apex_available:platform", - "com.android.bluetooth", + "com.android.btservices", "com.android.virt", ], min_sdk_version: "29", 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, -- cgit v1.2.3 From ba88b3a01b6148eb1fe92c63e45eddce201c8f63 Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Mon, 12 Dec 2022 18:20:40 +0100 Subject: Upgrade lock_api to 0.4.9 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 Test: TreeHugger Change-Id: I3581e94a77339cb2a9e5453fbbf1038ec1cb0d84 --- .cargo_vcs_info.json | 2 +- Android.bp | 3 ++- Cargo.toml | 20 ++++++++++++++++---- Cargo.toml.orig | 7 +++++-- METADATA | 12 ++++++++---- build.rs | 7 +++++++ src/lib.rs | 3 --- src/mutex.rs | 44 +++++++++++++++++++++++++++++++++++++++----- src/remutex.rs | 12 ++++++------ src/rwlock.rs | 16 ++++++++-------- 10 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 build.rs 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 diff --git a/Android.bp b/Android.bp index 35f09bc..50d28ce 100644 --- a/Android.bp +++ b/Android.bp @@ -42,9 +42,10 @@ 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", ], diff --git a/Cargo.toml b/Cargo.toml index 63cf8c3..b1ff8c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,22 @@ [package] edition = "2018" name = "lock_api" -version = "0.4.6" +version = "0.4.9" authors = ["Amanieu d'Antras "] 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 "] 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 = [] diff --git a/METADATA b/METADATA index 1caadde..e0c7e81 100644 --- a/METADATA +++ b/METADATA @@ -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/src/lib.rs b/src/lib.rs index c99c68b..cfa53bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 Sync for Mutex {} impl Mutex { /// 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 { Mutex { @@ -159,7 +159,7 @@ impl Mutex { } /// 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 { 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 { mutex: Arc>, - marker: PhantomData, + marker: PhantomData<*const ()>, +} + +#[cfg(feature = "arc_lock")] +unsafe impl Send for ArcMutexGuard where + R::GuardMarker: Send +{ +} +#[cfg(feature = "arc_lock")] +unsafe impl Sync for ArcMutexGuard where + R::GuardMarker: Sync +{ } #[cfg(feature = "arc_lock")] impl ArcMutexGuard { /// Returns a reference to the `Mutex` this is guarding, contained in its `Arc`. #[inline] - pub fn mutex(&self) -> &Arc> { - &self.mutex + pub fn mutex(s: &Self) -> &Arc> { + &s.mutex + } + + /// Unlocks the mutex and returns the `Arc` that was held by the [`ArcMutexGuard`]. + #[inline] + pub fn into_arc(s: Self) -> Arc> { + // 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 Sync impl ReentrantMutex { /// 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 { ReentrantMutex { @@ -245,7 +245,7 @@ impl ReentrantMutex { } /// 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 { 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( @@ -654,10 +654,10 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGu f: F, ) -> Result, 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( 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 Sync for RwLock impl RwLock { /// Creates a new instance of an `RwLock` which is unlocked. - #[cfg(feature = "nightly")] + #[cfg(has_const_fn_trait_bound)] #[inline] pub const fn new(val: T) -> RwLock { RwLock { @@ -376,7 +376,7 @@ impl RwLock { } /// Creates a new instance of an `RwLock` which is unlocked. - #[cfg(not(feature = "nightly"))] + #[cfg(not(has_const_fn_trait_bound))] #[inline] pub fn new(val: T) -> RwLock { RwLock { @@ -892,7 +892,7 @@ impl RwLock { /// 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) -> Option> { @@ -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(s: Self, f: F) -> Result, 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(s: Self, f: F) -> Result, 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(s: Self, f: F) -> Result, 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(s: Self, f: F) -> Result, Self> -- cgit v1.2.3 From c7e7861d44dac7769d26d5ddaf281570f9d8fd00 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Tue, 7 Mar 2023 17:24:12 -0800 Subject: Make lock_api available to product and vendor Bug: 270690570 Test: mma in external/rust/crates Change-Id: I63b86b245e7cbec5393636083e39059229d17ac5 --- Android.bp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Android.bp b/Android.bp index 50d28ce..06c2d2f 100644 --- a/Android.bp +++ b/Android.bp @@ -54,5 +54,7 @@ rust_library { "com.android.btservices", "com.android.virt", ], + product_available: true, + vendor_available: true, min_sdk_version: "29", } -- cgit v1.2.3