fix doc comment for counter

This commit is contained in:
fakeshadow 2021-04-29 00:46:05 +08:00
parent 112bc18bd3
commit 02f4ed7037
1 changed files with 12 additions and 9 deletions

View File

@ -58,20 +58,23 @@ fn handle_pair(
(accept, server)
}
/// counter: Arc<AtomicUsize> field is owned by Accept thread and ServerWorker thread.
/// counter: Arc<AtomicUsize> field is owned by `Accept` thread and `ServerWorker` thread.
///
/// Accept would increment the counter and ServerWorker would decrement it.
/// `Accept` would increment the counter and `ServerWorker` would decrement it.
///
/// Accept would mark ServerWorker as unable to accept work when the counter hitting limit.
/// ServerWorker would wake up Accept with mio::Waker and notify it ServerWorker is able to
/// accept more work.
/// # Atomic Ordering:
///
/// The atomic ordering of the two threads is not important.
/// `Accept` always look into it's cached `Availability` field for `ServerWorker` state.
/// It lazily increment counter after successful dispatching new work to `ServerWorker`.
/// On reaching counter limit `Accept` update it's cached `Availability` and mark worker as
/// unable to accept any work.
///
/// Reason:
///
/// Accept always look into it's cached `Availability` field for ServerWorker state.
/// `ServerWorker` always decrement the counter when every work received from `Accept` is done.
/// On reaching counter limit worker would use `mio::Waker` and `WakerQueue` to wake up `Accept`
/// and notify it to update cached `Availability` again to mark worker as able to accept work again.
///
/// Hense a wake up would only happen after `Accept` increment it to limit.
/// And a decrement to limit always wake up `Accept`.
#[derive(Clone)]
pub(crate) struct Counter {
counter: Arc<AtomicUsize>,