@@ -17,7 +17,7 @@ use super::Worker::Worker;
1717use crate :: {
1818 Queue :: StealingQueue :: StealingQueue ,
1919 Scheduler :: SchedulerBuilder :: Concurrency ,
20- Task :: { Priority :: Priority , Task :: Task } ,
20+ Task :: { Priority :: Enum , Task :: Struct } ,
2121} ;
2222
2323/// Manages a pool of worker threads and a work-stealing queue to execute tasks
@@ -36,21 +36,25 @@ impl Scheduler {
3636 /// This is a crate-private function, intended to be called only by the
3737 /// `SchedulerBuilder`.
3838 ///
39- /// @param NumberOfWorkers - The number of worker threads to spawn.
40- /// @param QueueConfigs - Configuration for named queues with concurrency
39+ /// @param number_of_workers - The number of worker threads to spawn.
40+ /// @param _queue_configs - Configuration for named queues with concurrency
4141 /// limits (future use).
42- pub ( crate ) fn Start ( NumberOfWorkers : usize , _QueueConfigs : HashMap < String , Concurrency > ) -> Self {
43- info ! ( "[Scheduler] Starting scheduler with {} worker threads." , NumberOfWorkers ) ;
42+ pub ( crate ) fn Start ( number_of_workers : usize , _queue_configs : HashMap < String , Concurrency > ) -> Self {
43+ info ! ( "[Scheduler] Starting scheduler with {} worker threads." , number_of_workers ) ;
4444 let IsRunning = Arc :: new ( AtomicBool :: new ( true ) ) ;
45- let Queue = Arc :: new ( StealingQueue :: New ( NumberOfWorkers ) ) ;
45+ let Queue = Arc :: new ( StealingQueue :: New ( number_of_workers ) ) ;
4646
47- let mut WorkerHandles = Vec :: with_capacity ( NumberOfWorkers ) ;
47+ let mut WorkerHandles = Vec :: with_capacity ( number_of_workers) ;
48+
49+ for WorkerIdentifier in 0 ..number_of_workers {
50+ let CloneQueue = Queue . clone ( ) ;
51+ let CloneIsRunning = IsRunning . clone ( ) ;
4852
49- for WorkerId in 0 ..NumberOfWorkers {
50- let WorkerInstance = Worker :: New ( WorkerId , Queue . clone ( ) , IsRunning . clone ( ) ) ;
5153 let WorkerHandle = tokio:: spawn ( async move {
54+ let WorkerInstance = Worker :: New ( WorkerIdentifier , CloneQueue , CloneIsRunning ) ;
5255 WorkerInstance . Run ( ) . await ;
5356 } ) ;
57+
5458 WorkerHandles . push ( WorkerHandle ) ;
5559 }
5660
@@ -60,28 +64,28 @@ impl Scheduler {
6064 /// Submits a new task (as a `Future`) to the scheduler's global queue.
6165 /// The task will be picked up by the next available worker.
6266 ///
63- /// @param FutureInstance - The async block or function to execute.
64- /// @param TaskPriority - The priority of the task.
65- pub fn Submit < F > ( & self , FutureInstance : F , TaskPriority : Priority )
67+ /// @param future_instance - The async block or function to execute.
68+ /// @param task_priority - The priority of the task.
69+ pub fn submit < F > ( & self , future_instance : F , task_priority : Enum )
6670 where
6771 F : Future < Output = ( ) > + Send + ' static , {
68- let NewTask = Task :: New ( FutureInstance , TaskPriority ) ;
69- self . Queue . Push ( NewTask ) ;
72+ let new_task = Struct :: New ( future_instance , task_priority ) ;
73+ self . Queue . Push ( new_task ) ;
7074 }
7175
7276 /// Asynchronously shuts down the scheduler.
7377 ///
7478 /// This signals all worker threads to stop their loops and then waits for
7579 /// them to complete their current tasks and exit gracefully.
76- pub async fn Shutdown ( & mut self ) {
80+ pub async fn ShutDown ( & mut self ) {
7781 if !self . IsRunning . swap ( false , Ordering :: Relaxed ) {
78- info ! ( "[Scheduler] Shutdown already initiated." ) ;
82+ info ! ( "[Scheduler] ShutDown already initiated." ) ;
7983 return ;
8084 }
8185
8286 info ! ( "[Scheduler] Shutting down worker threads..." ) ;
83- for Handle in self . WorkerHandles . drain ( ..) {
84- if let Err ( e) = Handle . await {
87+ for handle in self . WorkerHandles . drain ( ..) {
88+ if let Err ( e) = handle . await {
8589 error ! ( "[Scheduler] Error joining worker task during shutdown: {}" , e) ;
8690 }
8791 }
0 commit comments