summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync/mpsc
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-01-03 10:34:15 -0800
committerGitHub <noreply@github.com>2020-01-03 10:34:15 -0800
commitefcbf9613f2d5048550f9c828e3be422644f1391 (patch)
treef8c77a9d21c57f80ed989d16839acffe850baf77 /tokio/src/sync/mpsc
parent3736467dbb74ea6d14091cf1cac3ce08e1fcb911 (diff)
sync: add batch op support to internal semaphore (#2004)
Extend internal semaphore to support batch operations. With this PR, consumers of the semaphore are able to atomically request more than one permit. This is useful for implementing a RwLock.
Diffstat (limited to 'tokio/src/sync/mpsc')
-rw-r--r--tokio/src/sync/mpsc/chan.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/tokio/src/sync/mpsc/chan.rs b/tokio/src/sync/mpsc/chan.rs
index 7a15e8b3..847a0b70 100644
--- a/tokio/src/sync/mpsc/chan.rs
+++ b/tokio/src/sync/mpsc/chan.rs
@@ -408,7 +408,7 @@ impl Semaphore for (crate::sync::semaphore_ll::Semaphore, usize) {
}
fn drop_permit(&self, permit: &mut Permit) {
- permit.release(&self.0);
+ permit.release(1, &self.0);
}
fn add_permit(&self) {
@@ -425,17 +425,17 @@ impl Semaphore for (crate::sync::semaphore_ll::Semaphore, usize) {
permit: &mut Permit,
) -> Poll<Result<(), ClosedError>> {
permit
- .poll_acquire(cx, &self.0)
+ .poll_acquire(cx, 1, &self.0)
.map_err(|_| ClosedError::new())
}
fn try_acquire(&self, permit: &mut Permit) -> Result<(), TrySendError> {
- permit.try_acquire(&self.0)?;
+ permit.try_acquire(1, &self.0)?;
Ok(())
}
fn forget(&self, permit: &mut Self::Permit) {
- permit.forget()
+ permit.forget(1);
}
fn close(&self) {