• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qubit-ltd / rs-thread-pool / 3a36bb21-f016-42e2-841a-881531136b96

03 May 2026 06:30PM UTC coverage: 98.309% (-0.07%) from 98.375%
3a36bb21-f016-42e2-841a-881531136b96

push

circleci

Haixing-Hu
chore(ci): align CI configuration

1512 of 1538 relevant lines covered (98.31%)

37.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/queue_steal_source.rs
1
/*******************************************************************************
2
 *
3
 *    Copyright (c) 2025 - 2026 Haixing Hu.
4
 *
5
 *    SPDX-License-Identifier: Apache-2.0
6
 *
7
 *    Licensed under the Apache License, Version 2.0.
8
 *
9
 ******************************************************************************/
10
//! Queue stealing adapters for fixed-pool worker queues.
11

12
use crossbeam_deque::{
13
    Injector,
14
    Steal,
15
    Stealer,
16
    Worker,
17
};
18

19
use crate::thread_pool::PoolJob;
20

21
/// Steals one job with immediate retry on transient contention.
22
///
23
/// # Parameters
24
///
25
/// * `source` - Queue source to probe.
26
///
27
/// # Returns
28
///
29
/// `Some(job)` when the source contains a job, otherwise `None`.
30
pub(crate) fn steal_one<S>(source: &S) -> Option<PoolJob>
353✔
31
where
353✔
32
    S: QueueStealSource,
353✔
33
{
34
    retry_steal(|| source.steal_one())
353✔
35
}
353✔
36

37
/// Steals a batch into `dest` and returns one job.
38
///
39
/// # Parameters
40
///
41
/// * `source` - Queue source that may provide one or more jobs.
42
/// * `dest` - Owner-local deque receiving any stolen batch remainder.
43
///
44
/// # Returns
45
///
46
/// `Some(job)` when the source or destination yields a job, otherwise `None`.
47
pub(crate) fn steal_batch_and_pop<S>(source: &S, dest: &Worker<PoolJob>) -> Option<PoolJob>
74✔
48
where
74✔
49
    S: QueueStealSource,
74✔
50
{
51
    retry_steal(|| source.steal_batch_and_pop(dest))
74✔
52
}
74✔
53

54
/// Retries transient steal contention until a stable result is observed.
55
///
56
/// # Parameters
57
///
58
/// * `steal` - Steal operation to invoke until it succeeds or reports empty.
59
///
60
/// # Returns
61
///
62
/// `Some(job)` when a job is stolen, otherwise `None` when the source is empty.
63
fn retry_steal<F>(mut steal: F) -> Option<PoolJob>
427✔
64
where
427✔
65
    F: FnMut() -> Steal<PoolJob>,
427✔
66
{
67
    loop {
68
        match steal() {
427✔
69
            Steal::Success(job) => return Some(job),
297✔
70
            Steal::Empty => return None,
130✔
71
            Steal::Retry => continue,
×
72
        }
73
    }
74
}
427✔
75

76
/// Small adapter trait over crossbeam steal sources used by pool queues.
77
pub(crate) trait QueueStealSource {
78
    /// Steals one job from this source.
79
    fn steal_one(&self) -> Steal<PoolJob>;
80

81
    /// Steals a batch into `dest` and pops one job from `dest`.
82
    fn steal_batch_and_pop(&self, dest: &Worker<PoolJob>) -> Steal<PoolJob>;
83
}
84

85
impl QueueStealSource for Injector<PoolJob> {
86
    #[inline]
87
    fn steal_one(&self) -> Steal<PoolJob> {
322✔
88
        self.steal()
322✔
89
    }
322✔
90

91
    #[inline]
92
    fn steal_batch_and_pop(&self, dest: &Worker<PoolJob>) -> Steal<PoolJob> {
70✔
93
        Injector::steal_batch_and_pop(self, dest)
70✔
94
    }
70✔
95
}
96

97
impl QueueStealSource for Stealer<PoolJob> {
98
    #[inline]
99
    fn steal_one(&self) -> Steal<PoolJob> {
31✔
100
        self.steal()
31✔
101
    }
31✔
102

103
    #[inline]
104
    fn steal_batch_and_pop(&self, dest: &Worker<PoolJob>) -> Steal<PoolJob> {
4✔
105
        Stealer::steal_batch_and_pop(self, dest)
4✔
106
    }
4✔
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc