Skip to content

Commit e06178f

Browse files
authored
[ISSUE mxsm#2312]Adding #[inline] for CountDownLatch methods. (mxsm#2313)
1 parent 94d1532 commit e06178f

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

rocketmq/src/count_down_latch.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,16 @@ pub struct CountDownLatch {
3131
}
3232

3333
impl CountDownLatch {
34-
/// Creates a new `CountDownLatch` initialized with the given count.
35-
///
36-
/// # Arguments
37-
///
38-
/// * `count` - The number of times `count_down` must be invoked before tasks can pass through
39-
/// `wait`.
40-
///
41-
/// # Returns
42-
///
4334
/// A new `CountDownLatch`.
35+
#[inline]
4436
pub fn new(count: u32) -> Self {
4537
CountDownLatch {
4638
count: Arc::new(Mutex::new(count)),
4739
notify: Arc::new(Notify::new()),
4840
}
4941
}
5042

51-
/// Decrements the count of the latch, releasing all waiting tasks if the count reaches zero.
52-
///
53-
/// This method is asynchronous and will lock the internal count before decrementing it.
43+
#[inline]
5444
pub async fn count_down(&self) {
5545
let mut count = self.count.lock().await;
5646
*count -= 1;
@@ -59,9 +49,7 @@ impl CountDownLatch {
5949
}
6050
}
6151

62-
/// Waits until the count reaches zero.
63-
///
64-
/// This method is asynchronous and will block the current task until the count reaches zero.
52+
#[inline]
6553
pub async fn wait(&self) {
6654
let count = self.count.lock().await;
6755
if *count > 0 {
@@ -70,18 +58,7 @@ impl CountDownLatch {
7058
}
7159
}
7260

73-
/// Waits until the count reaches zero or the specified timeout elapses.
74-
///
75-
/// This method is asynchronous and will block the current task until the count reaches zero
76-
/// or the timeout elapses.
77-
///
78-
/// # Arguments
79-
///
80-
/// * `timeout` - The maximum duration to wait for the count to reach zero.
81-
///
82-
/// # Returns
83-
///
84-
/// `true` if the count reached zero before the timeout elapsed, `false` otherwise.
61+
#[inline]
8562
pub async fn wait_timeout(&self, timeout: Duration) -> bool {
8663
tokio::time::timeout(timeout, self.wait()).await.is_ok()
8764
}

0 commit comments

Comments
 (0)