summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync/mutex.rs
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/mutex.rs
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/mutex.rs')
-rw-r--r--tokio/src/sync/mutex.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/tokio/src/sync/mutex.rs b/tokio/src/sync/mutex.rs
index fe891159..48451357 100644
--- a/tokio/src/sync/mutex.rs
+++ b/tokio/src/sync/mutex.rs
@@ -156,7 +156,7 @@ impl<T> Mutex<T> {
lock: self,
permit: semaphore::Permit::new(),
};
- poll_fn(|cx| guard.permit.poll_acquire(cx, &self.s))
+ poll_fn(|cx| guard.permit.poll_acquire(cx, 1, &self.s))
.await
.unwrap_or_else(|_| {
// The semaphore was closed. but, we never explicitly close it, and we have a
@@ -169,7 +169,7 @@ impl<T> Mutex<T> {
/// Try to acquire the lock
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
let mut permit = semaphore::Permit::new();
- match permit.try_acquire(&self.s) {
+ match permit.try_acquire(1, &self.s) {
Ok(_) => Ok(MutexGuard { lock: self, permit }),
Err(_) => Err(TryLockError(())),
}
@@ -178,7 +178,7 @@ impl<T> Mutex<T> {
impl<'a, T> Drop for MutexGuard<'a, T> {
fn drop(&mut self) {
- self.permit.release(&self.lock.s);
+ self.permit.release(1, &self.lock.s);
}
}