1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Provides functionality for creating work-stealing queues.
//!
//! This module sets up a work-stealing system with an injector queue and per-worker queues.
//! It uses the `crossbeam::deque` crate to implement efficient task distribution and load balancing
//! among workers, with support for optional metrics collection.
use ;
use Arc;
use crateMetricsCollector;
/// Creates a set of work-stealing queues for task distribution.
///
/// This function initializes:
/// - An `Injector<T>` queue for global task injection.
/// - A vector of `Stealer<T>` instances, each associated with a worker thread.
/// - A vector of `Worker<T>` instances, one for each worker thread.
///
/// Each worker has its own local queue and a `Stealer` that allows other workers
/// to steal tasks when their own queues are empty. The `Injector` acts as a global
/// task queue, distributing tasks to the workers.
///
/// # Arguments
/// - `num_workers`: The number of worker threads to create.
/// - `metrics_collector`: An optional `MetricsCollector` instance to monitor worker activity.
///
/// # Returns
/// A tuple containing:
/// - An `Arc<Injector<T>>`: The global task injector queue.
/// - A `Vec<Stealer<T>>`: A vector of `Stealer` instances for each worker thread.
/// - A `Vec<Worker<T>>`: A vector of worker queues.
///
/// # Type Parameters
/// - `T`: The type of tasks managed by the queues.
///
/// # Example (internal usage)
/// ```ignore
/// let (injector, stealers, workers) = work_stealing_queues(4, None);
/// ```