Snap for 7199817 from 974f87cdb36060fe9b8fbae77c546574a54c3af4 to s-keystone-qcom-release

Change-Id: I45d70841649e1db6419f2a43ba47868b89edc63e
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
new file mode 100644
index 0000000..4fd4ba3
--- /dev/null
+++ b/.cargo_vcs_info.json
@@ -0,0 +1,5 @@
+{
+  "git": {
+    "sha1": "1d53a29ec16ccd5b094fb205edb73591455eb4b6"
+  }
+}
diff --git a/Android.bp b/Android.bp
index a8f25b5..355f9d8 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,5 +1,45 @@
 // This file is generated by cargo2android.py --run --dependencies --device --patch=patches/Android.bp.patch.
 
+package {
+    default_applicable_licenses: [
+        "external_rust_crates_futures-channel_license",
+    ],
+}
+
+// Added automatically by a large-scale-change that took the approach of
+// 'apply every license found to every target'. While this makes sure we respect
+// every license restriction, it may not be entirely correct.
+//
+// e.g. GPL in an MIT project might only apply to the contrib/ directory.
+//
+// Please consider splitting the single license below into multiple licenses,
+// taking care not to lose any license_kind information, and overriding the
+// default license using the 'licenses: [...]' property on targets as needed.
+//
+// For unused files, consider creating a 'fileGroup' with "//visibility:private"
+// to attach the license to, and including a comment whether the files may be
+// used in the current project.
+//
+// large-scale-change included anything that looked like it might be a license
+// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
+//
+// Please consider removing redundant or irrelevant files from 'license_text:'.
+// See: http://go/android-license-faq
+license {
+    name: "external_rust_crates_futures-channel_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-Apache-2.0",
+        "SPDX-license-identifier-BSD",
+        "SPDX-license-identifier-MIT",
+    ],
+    license_text: [
+        "LICENSE",
+        "LICENSE-APACHE",
+        "LICENSE-MIT",
+    ],
+}
+
 rust_library {
     name: "libfutures_channel",
     host_supported: true,
@@ -21,4 +61,4 @@
 }
 
 // dependent_library ["feature_list"]
-//   futures-core-0.3.8 "alloc,std"
+//   futures-core-0.3.12 "alloc,std"
diff --git a/Cargo.toml b/Cargo.toml
index e5feaad..494deb5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,25 +13,27 @@
 [package]
 edition = "2018"
 name = "futures-channel"
-version = "0.3.7"
+version = "0.3.12"
 authors = ["Alex Crichton <alex@alexcrichton.com>"]
 description = "Channels for asynchronous communication using futures-rs.\n"
 homepage = "https://rust-lang.github.io/futures-rs"
-documentation = "https://docs.rs/futures-channel/0.3.7"
+documentation = "https://docs.rs/futures-channel/0.3"
 license = "MIT OR Apache-2.0"
 repository = "https://github.com/rust-lang/futures-rs"
 [package.metadata.docs.rs]
 all-features = true
 rustdoc-args = ["--cfg", "docsrs"]
 [dependencies.futures-core]
-version = "0.3.7"
+version = "0.3.12"
 default-features = false
 
 [dependencies.futures-sink]
-version = "0.3.7"
+version = "0.3.12"
 optional = true
 default-features = false
 
+[dev-dependencies]
+
 [features]
 alloc = ["futures-core/alloc"]
 cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic"]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 76aef73..5b4c639 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,12 +1,12 @@
 [package]
 name = "futures-channel"
 edition = "2018"
-version = "0.3.7"
+version = "0.3.12"
 authors = ["Alex Crichton <alex@alexcrichton.com>"]
 license = "MIT OR Apache-2.0"
 repository = "https://github.com/rust-lang/futures-rs"
 homepage = "https://rust-lang.github.io/futures-rs"
-documentation = "https://docs.rs/futures-channel/0.3.7"
+documentation = "https://docs.rs/futures-channel/0.3"
 description = """
 Channels for asynchronous communication using futures-rs.
 """
@@ -24,8 +24,12 @@
 cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic"]
 
 [dependencies]
-futures-core = { path = "../futures-core", version = "0.3.7", default-features = false }
-futures-sink = { path = "../futures-sink", version = "0.3.7", default-features = false, optional = true }
+futures-core = { path = "../futures-core", version = "0.3.12", default-features = false }
+futures-sink = { path = "../futures-sink", version = "0.3.12", default-features = false, optional = true }
+
+[dev-dependencies]
+futures = { path = "../futures", default-features = true }
+futures-test = { path = "../futures-test", default-features = true }
 
 [package.metadata.docs.rs]
 all-features = true
diff --git a/METADATA b/METADATA
index ea8e204..7481020 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/futures-channel/futures-channel-0.3.7.crate"
+    value: "https://static.crates.io/crates/futures-channel/futures-channel-0.3.12.crate"
   }
-  version: "0.3.7"
+  version: "0.3.12"
   license_type: NOTICE
   last_upgrade_date {
-    year: 2020
-    month: 10
-    day: 25
+    year: 2021
+    month: 2
+    day: 9
   }
 }
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 7d1919a..7e10dd0 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,11 +1,7 @@
-// Generated by cargo2android.py for tests in Android.bp
+// Generated by update_crate_tests.py for tests that depend on this crate.
 {
   "presubmit": [
     {
-      "host": true,
-      "name": "futures-util_host_test_src_lib"
-    },
-    {
       "name": "futures-util_device_test_src_lib"
     }
   ]
diff --git a/src/lib.rs b/src/lib.rs
index f8be701..22d90d8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,9 +1,14 @@
 //! Asynchronous channels.
 //!
-//! This crate provides channels that can be used to communicate between
-//! asynchronous tasks.
+//! Like threads, concurrent tasks sometimes need to communicate with each
+//! other. This module contains two basic abstractions for doing so:
 //!
-//! All items of this library are only available when the `std` or `alloc` feature of this
+//! - [oneshot], a way of sending a single value from one task to another.
+//! - [mpsc], a multi-producer, single-consumer channel for sending values
+//!   between tasks, analogous to the similarly-named structure in the standard
+//!   library.
+//!
+//! All items are only available when the `std` or `alloc` feature of this
 //! library is activated, and it is activated by default.
 
 #![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
@@ -14,16 +19,8 @@
 // It cannot be included in the published code because this lints have false positives in the minimum required version.
 #![cfg_attr(test, warn(single_use_lifetimes))]
 #![warn(clippy::all)]
-
-// mem::take requires Rust 1.40, matches! requires Rust 1.42
-// Can be removed if the minimum supported version increased or if https://github.com/rust-lang/rust-clippy/issues/3941
-// get's implemented.
-#![allow(clippy::mem_replace_with_default, clippy::match_like_matches_macro)]
-
 #![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
 
-#![doc(html_root_url = "https://docs.rs/futures-channel/0.3.7")]
-
 #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
 compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
 
diff --git a/src/lock.rs b/src/lock.rs
index e477369..5eecdd9 100644
--- a/src/lock.rs
+++ b/src/lock.rs
@@ -36,8 +36,8 @@
 
 impl<T> Lock<T> {
     /// Creates a new lock around the given value.
-    pub(crate) fn new(t: T) -> Lock<T> {
-        Lock {
+    pub(crate) fn new(t: T) -> Self {
+        Self {
             locked: AtomicBool::new(false),
             data: UnsafeCell::new(t),
         }
diff --git a/src/mpsc/mod.rs b/src/mpsc/mod.rs
index 64c551e..494c97b 100644
--- a/src/mpsc/mod.rs
+++ b/src/mpsc/mod.rs
@@ -334,7 +334,7 @@
 
 impl SenderTask {
     fn new() -> Self {
-        SenderTask {
+        Self {
             task: None,
             is_parked: false,
         }
@@ -483,7 +483,7 @@
 
     /// Returns whether the sender send to this receiver.
     fn is_connected_to(&self, inner: &Arc<UnboundedInner<T>>) -> bool {
-        Arc::ptr_eq(&self.inner, &inner)
+        Arc::ptr_eq(&self.inner, inner)
     }
 
     /// Returns pointer to the Arc containing sender
@@ -664,8 +664,8 @@
 
     /// Returns whether the sender send to this receiver.
     fn is_connected_to(&self, receiver: &Arc<BoundedInner<T>>) -> bool {
-        Arc::ptr_eq(&self.inner, &receiver)
-    } 
+        Arc::ptr_eq(&self.inner, receiver)
+    }
 
     /// Returns pointer to the Arc containing sender
     ///
@@ -896,19 +896,19 @@
 }
 
 impl<T> Clone for Sender<T> {
-    fn clone(&self) -> Sender<T> {
-        Sender(self.0.clone())
+    fn clone(&self) -> Self {
+        Self(self.0.clone())
     }
 }
 
 impl<T> Clone for UnboundedSender<T> {
-    fn clone(&self) -> UnboundedSender<T> {
-        UnboundedSender(self.0.clone())
+    fn clone(&self) -> Self {
+        Self(self.0.clone())
     }
 }
 
 impl<T> Clone for UnboundedSenderInner<T> {
-    fn clone(&self) -> UnboundedSenderInner<T> {
+    fn clone(&self) -> Self {
         // Since this atomic op isn't actually guarding any memory and we don't
         // care about any orderings besides the ordering on the single atomic
         // variable, a relaxed ordering is acceptable.
@@ -923,23 +923,22 @@
             debug_assert!(curr < MAX_BUFFER);
 
             let next = curr + 1;
-            let actual = self.inner.num_senders.compare_and_swap(curr, next, SeqCst);
-
-            // The ABA problem doesn't matter here. We only care that the
-            // number of senders never exceeds the maximum.
-            if actual == curr {
-                return UnboundedSenderInner {
-                    inner: self.inner.clone(),
-                };
+            match self.inner.num_senders.compare_exchange(curr, next, SeqCst, SeqCst) {
+                Ok(_) => {
+                    // The ABA problem doesn't matter here. We only care that the
+                    // number of senders never exceeds the maximum.
+                    return Self {
+                        inner: self.inner.clone(),
+                    };
+                }
+                Err(actual) => curr = actual,
             }
-
-            curr = actual;
         }
     }
 }
 
 impl<T> Clone for BoundedSenderInner<T> {
-    fn clone(&self) -> BoundedSenderInner<T> {
+    fn clone(&self) -> Self {
         // Since this atomic op isn't actually guarding any memory and we don't
         // care about any orderings besides the ordering on the single atomic
         // variable, a relaxed ordering is acceptable.
@@ -954,19 +953,18 @@
             debug_assert!(curr < self.inner.max_senders());
 
             let next = curr + 1;
-            let actual = self.inner.num_senders.compare_and_swap(curr, next, SeqCst);
-
-            // The ABA problem doesn't matter here. We only care that the
-            // number of senders never exceeds the maximum.
-            if actual == curr {
-                return BoundedSenderInner {
-                    inner: self.inner.clone(),
-                    sender_task: Arc::new(Mutex::new(SenderTask::new())),
-                    maybe_parked: false,
-                };
+            match self.inner.num_senders.compare_exchange(curr, next, SeqCst, SeqCst) {
+                Ok(_) => {
+                    // The ABA problem doesn't matter here. We only care that the
+                    // number of senders never exceeds the maximum.
+                    return Self {
+                        inner: self.inner.clone(),
+                        sender_task: Arc::new(Mutex::new(SenderTask::new())),
+                        maybe_parked: false,
+                    };
+                }
+                Err(actual) => curr = actual,
             }
-
-            curr = actual;
         }
     }
 }
diff --git a/src/mpsc/queue.rs b/src/mpsc/queue.rs
index 353e75e..b00e1b1 100644
--- a/src/mpsc/queue.rs
+++ b/src/mpsc/queue.rs
@@ -63,7 +63,7 @@
 
 #[derive(Debug)]
 struct Node<T> {
-    next: AtomicPtr<Node<T>>,
+    next: AtomicPtr<Self>,
     value: Option<T>,
 }
 
@@ -80,8 +80,8 @@
 unsafe impl<T: Send> Sync for Queue<T> { }
 
 impl<T> Node<T> {
-    unsafe fn new(v: Option<T>) -> *mut Node<T> {
-        Box::into_raw(Box::new(Node {
+    unsafe fn new(v: Option<T>) -> *mut Self {
+        Box::into_raw(Box::new(Self {
             next: AtomicPtr::new(ptr::null_mut()),
             value: v,
         }))
@@ -91,9 +91,9 @@
 impl<T> Queue<T> {
     /// Creates a new queue that is safe to share among multiple producers and
     /// one consumer.
-    pub(super) fn new() -> Queue<T> {
+    pub(super) fn new() -> Self {
         let stub = unsafe { Node::new(None) };
-        Queue {
+        Self {
             head: AtomicPtr::new(stub),
             tail: UnsafeCell::new(stub),
         }
diff --git a/src/mpsc/sink_impl.rs b/src/mpsc/sink_impl.rs
index e7f5457..4ce66b4 100644
--- a/src/mpsc/sink_impl.rs
+++ b/src/mpsc/sink_impl.rs
@@ -49,14 +49,14 @@
         self: Pin<&mut Self>,
         cx: &mut Context<'_>,
     ) -> Poll<Result<(), Self::Error>> {
-        UnboundedSender::poll_ready(&*self, cx)
+        Self::poll_ready(&*self, cx)
     }
 
     fn start_send(
         mut self: Pin<&mut Self>,
         msg: T,
     ) -> Result<(), Self::Error> {
-        UnboundedSender::start_send(&mut *self, msg)
+        Self::start_send(&mut *self, msg)
     }
 
     fn poll_flush(
diff --git a/src/oneshot.rs b/src/oneshot.rs
index 47d3ada..dbbce81 100644
--- a/src/oneshot.rs
+++ b/src/oneshot.rs
@@ -7,7 +7,7 @@
 use core::pin::Pin;
 use core::sync::atomic::AtomicBool;
 use core::sync::atomic::Ordering::SeqCst;
-use futures_core::future::Future;
+use futures_core::future::{Future, FusedFuture};
 use futures_core::task::{Context, Poll, Waker};
 
 use crate::lock::Lock;
@@ -116,8 +116,8 @@
 }
 
 impl<T> Inner<T> {
-    fn new() -> Inner<T> {
-        Inner {
+    fn new() -> Self {
+        Self {
             complete: AtomicBool::new(false),
             data: Lock::new(None),
             rx_task: Lock::new(None),
@@ -366,7 +366,7 @@
     /// [`Receiver`](Receiver) half has hung up.
     ///
     /// This is a utility wrapping [`poll_canceled`](Sender::poll_canceled)
-    /// to expose a [`Future`](core::future::Future). 
+    /// to expose a [`Future`](core::future::Future).
     pub fn cancellation(&mut self) -> Cancellation<'_, T> {
         Cancellation { inner: self }
     }
@@ -461,6 +461,21 @@
     }
 }
 
+impl<T> FusedFuture for Receiver<T> {
+    fn is_terminated(&self) -> bool {
+        if self.inner.complete.load(SeqCst) {
+            if let Some(slot) = self.inner.data.try_lock() {
+                if slot.is_some() {
+                    return false;
+                }
+            }
+            true
+        } else {
+            false
+        }
+    }
+}
+
 impl<T> Drop for Receiver<T> {
     fn drop(&mut self) {
         self.inner.drop_rx()