Snap for 10447354 from 12f68c351f6540352b8bbe53b468172980d31828 to mainline-cellbroadcast-release

Change-Id: I35d89fb8705b20641f9bdffaa9b81b1419989bce
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 67d3a3b..06c2d2f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -42,16 +42,19 @@
     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",
 }
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 <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 @@
 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 @@
 # 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 @@
   }
   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,
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 @@
 
 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 @@
     }
 
     /// 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 @@
         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 @@
 #[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 @@
 
 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 @@
     }
 
     /// 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 @@
     /// 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 @@
         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 @@
     /// 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 @@
 
 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 @@
     }
 
     /// 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 @@
     /// 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 @@
     }
 
     /// 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 @@
     /// 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 @@
     /// 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 @@
     /// 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>