@@ -28,10 +28,10 @@ pub const TASK_TIME_SLICE: u64 = 10_000;
28
28
29
29
static NO_TASKS : AtomicU32 = AtomicU32 :: new ( 0 ) ;
30
30
/// Map between Core ID and per-core scheduler
31
- static mut SCHEDULERS : Option < BTreeMap < CoreId , & PerCoreScheduler > > = None ;
31
+ static mut SCHEDULERS : BTreeMap < CoreId , & PerCoreScheduler > = BTreeMap :: new ( ) ;
32
32
/// Map between Task ID and Task Control Block
33
- static TASKS : SpinlockIrqSave < Option < BTreeMap < TaskId , VecDeque < TaskHandle > > > > =
34
- SpinlockIrqSave :: new ( None ) ;
33
+ static TASKS : SpinlockIrqSave < BTreeMap < TaskId , VecDeque < TaskHandle > > > =
34
+ SpinlockIrqSave :: new ( BTreeMap :: new ( ) ) ;
35
35
36
36
/// Unique identifier for a core.
37
37
pub type CoreId = u32 ;
@@ -95,11 +95,7 @@ impl PerCoreScheduler {
95
95
// Add it to the task lists.
96
96
let wakeup = {
97
97
let mut input_locked = get_scheduler ( core_id) . input . lock ( ) ;
98
- TASKS
99
- . lock ( )
100
- . as_mut ( )
101
- . unwrap ( )
102
- . insert ( tid, VecDeque :: with_capacity ( 1 ) ) ;
98
+ TASKS . lock ( ) . insert ( tid, VecDeque :: with_capacity ( 1 ) ) ;
103
99
NO_TASKS . fetch_add ( 1 , Ordering :: SeqCst ) ;
104
100
105
101
if core_id != core_scheduler ( ) . core_id {
@@ -183,11 +179,7 @@ impl PerCoreScheduler {
183
179
// Add it to the task lists.
184
180
let wakeup = {
185
181
let mut input_locked = get_scheduler ( core_id) . input . lock ( ) ;
186
- TASKS
187
- . lock ( )
188
- . as_mut ( )
189
- . unwrap ( )
190
- . insert ( tid, VecDeque :: with_capacity ( 1 ) ) ;
182
+ TASKS . lock ( ) . insert ( tid, VecDeque :: with_capacity ( 1 ) ) ;
191
183
NO_TASKS . fetch_add ( 1 , Ordering :: SeqCst ) ;
192
184
if core_id != core_scheduler ( ) . core_id {
193
185
input_locked. new_tasks . push_back ( clone_task. clone ( ) ) ;
@@ -345,7 +337,7 @@ impl PerCoreScheduler {
345
337
debug ! ( "Cleaning up task {}" , id) ;
346
338
347
339
// wakeup tasks, which are waiting for task with the identifier id
348
- match TASKS . lock ( ) . as_mut ( ) . unwrap ( ) . remove ( & id) {
340
+ match TASKS . lock ( ) . remove ( & id) {
349
341
Some ( mut queue) => {
350
342
while let Some ( task) = queue. pop_front ( ) {
351
343
result = true ;
@@ -502,22 +494,17 @@ impl PerCoreScheduler {
502
494
503
495
fn get_tid ( ) -> TaskId {
504
496
static TID_COUNTER : AtomicU32 = AtomicU32 :: new ( 0 ) ;
505
- let mut guard = TASKS . lock ( ) ;
497
+ let guard = TASKS . lock ( ) ;
506
498
507
499
loop {
508
500
let id = TaskId :: from ( TID_COUNTER . fetch_add ( 1 , Ordering :: SeqCst ) ) ;
509
- if !guard. as_mut ( ) . unwrap ( ) . contains_key ( & id) {
501
+ if !guard. contains_key ( & id) {
510
502
return id;
511
503
}
512
504
}
513
505
}
514
506
515
- pub fn init ( ) {
516
- unsafe {
517
- SCHEDULERS = Some ( BTreeMap :: new ( ) ) ;
518
- }
519
- * TASKS . lock ( ) = Some ( BTreeMap :: new ( ) ) ;
520
- }
507
+ pub fn init ( ) { }
521
508
522
509
#[ inline]
523
510
pub fn abort ( ) {
@@ -532,11 +519,7 @@ pub fn add_current_core() {
532
519
let idle_task = Rc :: new ( RefCell :: new ( Task :: new_idle ( tid, core_id) ) ) ;
533
520
534
521
// Add the ID -> Task mapping.
535
- TASKS
536
- . lock ( )
537
- . as_mut ( )
538
- . unwrap ( )
539
- . insert ( tid, VecDeque :: with_capacity ( 1 ) ) ;
522
+ TASKS . lock ( ) . insert ( tid, VecDeque :: with_capacity ( 1 ) ) ;
540
523
// Initialize a scheduler for this core.
541
524
debug ! (
542
525
"Initializing scheduler for core {} with idle task {}" ,
@@ -557,14 +540,14 @@ pub fn add_current_core() {
557
540
let scheduler = Box :: into_raw ( boxed_scheduler) ;
558
541
set_core_scheduler ( scheduler) ;
559
542
unsafe {
560
- SCHEDULERS . as_mut ( ) . unwrap ( ) . insert ( core_id, & ( * scheduler) ) ;
543
+ SCHEDULERS . insert ( core_id, & ( * scheduler) ) ;
561
544
}
562
545
}
563
546
564
547
#[ inline]
565
548
fn get_scheduler ( core_id : CoreId ) -> & ' static PerCoreScheduler {
566
549
// Get the scheduler for the desired core.
567
- if let Some ( result) = unsafe { SCHEDULERS . as_ref ( ) . unwrap ( ) . get ( & core_id) } {
550
+ if let Some ( result) = unsafe { SCHEDULERS . get ( & core_id) } {
568
551
result
569
552
} else {
570
553
panic ! (
@@ -585,7 +568,7 @@ pub fn join(id: TaskId) -> Result<(), ()> {
585
568
586
569
{
587
570
let mut guard = TASKS . lock ( ) ;
588
- match guard. as_mut ( ) . unwrap ( ) . get_mut ( & id) {
571
+ match guard. get_mut ( & id) {
589
572
Some ( queue) => {
590
573
queue. push_back ( core_scheduler. get_current_task_handle ( ) ) ;
591
574
core_scheduler. block_current_task ( None ) ;
0 commit comments