diff options
Diffstat (limited to 'src/watch/upstream.rs')
| -rw-r--r-- | src/watch/upstream.rs | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index c3e4954..888a5ed 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -143,25 +143,42 @@ static RUNNING: AtomicUsize = AtomicUsize::new(0); static SLOT_FREE: Condvar = Condvar::new(); static SLOT_LOCK: Mutex<()> = Mutex::new(()); -pub struct StageBSlot(()); +/// The real definition. The module is private, so this `pub` +/// is not a nameable path from outside; the alias below is the +/// only way to reach it, and the alias is what carries the +/// feature-conditional visibility. +mod stage_b_slot { + pub struct StageBSlot(()); -impl StageBSlot { - pub fn acquire(cap: usize) -> Self { - let cap = cap.max(1); - let guard = SLOT_LOCK.lock().unwrap_or_else(|e| e.into_inner()); - let mut guard = guard; - loop { - let n = RUNNING.load(Ordering::SeqCst); - if n < cap { - RUNNING.fetch_add(1, Ordering::SeqCst); - drop(guard); - return StageBSlot(()); + impl StageBSlot { + pub fn acquire(cap: usize) -> Self { + let cap = cap.max(1); + let guard = SLOT_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let mut guard = guard; + loop { + let n = RUNNING.load(Ordering::SeqCst); + if n < cap { + RUNNING.fetch_add(1, Ordering::SeqCst); + drop(guard); + return StageBSlot(()); + } + guard = SLOT_FREE.wait(guard).unwrap_or_else(|e| e.into_inner()); } - guard = SLOT_FREE.wait(guard).unwrap_or_else(|e| e.into_inner()); } } } +/// The stage-B concurrency slot. The VCS test that asserts it needs a real mirror, so it cannot move into the module. +/// +/// `pub` only under `test-support`. Production reaches the type +/// through its own module and never names it from outside; the +/// outside reader that needs the name is a test. +#[cfg(feature = "test-support")] +pub use stage_b_slot::StageBSlot; + +#[cfg(not(feature = "test-support"))] +pub(crate) use stage_b_slot::StageBSlot; + impl Drop for StageBSlot { fn drop(&mut self) { RUNNING.fetch_sub(1, Ordering::SeqCst); |
