@@ -16,11 +16,11 @@ use alloc::collections::vec_deque::VecDeque;
16
16
use alloc:: vec;
17
17
use executor:: AsyncTests ;
18
18
use static_cell:: StaticCell ;
19
- use zephyr:: kobj_define ;
19
+ use zephyr:: define_work_queue ;
20
20
use zephyr:: raw:: k_yield;
21
21
use zephyr:: sync:: { PinWeak , SpinMutex } ;
22
22
use zephyr:: time:: NoWait ;
23
- use zephyr:: work:: { SimpleAction , Work , WorkQueueBuilder } ;
23
+ use zephyr:: work:: { SimpleAction , Work } ;
24
24
use zephyr:: {
25
25
kconfig:: CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC ,
26
26
printkln,
@@ -80,7 +80,7 @@ extern "C" fn rust_main() {
80
80
spin_bench ( ) ;
81
81
sem_bench ( ) ;
82
82
83
- let simple = Simple :: new ( tester. workq . clone ( ) ) ;
83
+ let simple = Simple :: new ( tester. workq ) ;
84
84
let mut num = 6 ;
85
85
while num < 250 {
86
86
simple. run ( num, TOTAL_ITERS / num) ;
@@ -147,7 +147,7 @@ struct ThreadTests {
147
147
high_command : Sender < Command > ,
148
148
149
149
/// A work queue for the main runners.
150
- workq : Arc < WorkQueue > ,
150
+ workq : & ' static WorkQueue ,
151
151
152
152
/// The test also all return their result to the main. The threads Send, the main running
153
153
/// receives.
@@ -163,15 +163,7 @@ impl ThreadTests {
163
163
let ( low_send, low_recv) = bounded ( 1 ) ;
164
164
let ( high_send, high_recv) = bounded ( 1 ) ;
165
165
166
- let workq = Arc :: new (
167
- WorkQueueBuilder :: new ( )
168
- . set_priority ( 5 )
169
- . set_no_yield ( true )
170
- . start ( WORK_STACK . init_once ( ( ) ) . unwrap ( ) ) ,
171
- ) ;
172
-
173
- // Leak the workqueue so it doesn't get dropped.
174
- let _ = Arc :: into_raw ( workq. clone ( ) ) ;
166
+ let workq = WORKQ . start ( ) ;
175
167
176
168
let mut result = Self {
177
169
sems : & SEMS ,
@@ -581,20 +573,20 @@ enum TestResult {
581
573
582
574
/// The Simple test just does a ping pong test using manually submitted work.
583
575
struct Simple {
584
- workq : Arc < WorkQueue > ,
576
+ workq : & ' static WorkQueue ,
585
577
}
586
578
587
579
impl Simple {
588
- fn new ( workq : Arc < WorkQueue > ) -> Self {
580
+ fn new ( workq : & ' static WorkQueue ) -> Self {
589
581
Self { workq }
590
582
}
591
583
592
584
fn run ( & self , workers : usize , iterations : usize ) {
593
585
// printkln!("Running Simple");
594
- let main = Work :: new ( SimpleMain :: new ( workers * iterations, self . workq . clone ( ) ) ) ;
586
+ let main = Work :: new ( SimpleMain :: new ( workers * iterations, self . workq ) ) ;
595
587
596
588
let children: VecDeque < _ > = ( 0 ..workers)
597
- . map ( |n| Work :: new ( SimpleWorker :: new ( main. clone ( ) , self . workq . clone ( ) , n) ) )
589
+ . map ( |n| Work :: new ( SimpleWorker :: new ( main. clone ( ) , self . workq , n) ) )
598
590
. collect ( ) ;
599
591
600
592
let mut locked = main. action ( ) . locked . lock ( ) . unwrap ( ) ;
@@ -603,7 +595,7 @@ impl Simple {
603
595
604
596
let start = now ( ) ;
605
597
// Fire off main, which will run everything.
606
- Work :: submit_to_queue ( main. clone ( ) , & self . workq ) . unwrap ( ) ;
598
+ Work :: submit_to_queue ( main. clone ( ) , self . workq ) . unwrap ( ) ;
607
599
608
600
// And wait for the completion semaphore.
609
601
main. action ( ) . done . take ( Forever ) . unwrap ( ) ;
@@ -642,12 +634,12 @@ impl Simple {
642
634
/// A simple worker. When run, it submits the main worker to do the next work.
643
635
struct SimpleWorker {
644
636
main : PinWeak < Work < SimpleMain > > ,
645
- workq : Arc < WorkQueue > ,
637
+ workq : & ' static WorkQueue ,
646
638
_id : usize ,
647
639
}
648
640
649
641
impl SimpleWorker {
650
- fn new ( main : Pin < Arc < Work < SimpleMain > > > , workq : Arc < WorkQueue > , id : usize ) -> Self {
642
+ fn new ( main : Pin < Arc < Work < SimpleMain > > > , workq : & ' static WorkQueue , id : usize ) -> Self {
651
643
Self {
652
644
main : PinWeak :: downgrade ( main) ,
653
645
workq,
@@ -660,7 +652,7 @@ impl SimpleAction for SimpleWorker {
660
652
fn act ( self : Pin < & Self > ) {
661
653
// Each time we are run, fire the main worker back up.
662
654
let main = self . main . upgrade ( ) . unwrap ( ) ;
663
- Work :: submit_to_queue ( main. clone ( ) , & self . workq ) . unwrap ( ) ;
655
+ Work :: submit_to_queue ( main. clone ( ) , self . workq ) . unwrap ( ) ;
664
656
}
665
657
}
666
658
@@ -670,7 +662,7 @@ impl SimpleAction for SimpleWorker {
670
662
struct SimpleMain {
671
663
/// All of the work items.
672
664
locked : SpinMutex < Locked > ,
673
- workq : Arc < WorkQueue > ,
665
+ workq : & ' static WorkQueue ,
674
666
done : Semaphore ,
675
667
}
676
668
@@ -690,12 +682,12 @@ impl SimpleAction for SimpleMain {
690
682
lock. count -= 1 ;
691
683
drop ( lock) ;
692
684
693
- Work :: submit_to_queue ( worker. clone ( ) , & self . workq ) . unwrap ( ) ;
685
+ Work :: submit_to_queue ( worker. clone ( ) , self . workq ) . unwrap ( ) ;
694
686
}
695
687
}
696
688
697
689
impl SimpleMain {
698
- fn new ( count : usize , workq : Arc < WorkQueue > ) -> Self {
690
+ fn new ( count : usize , workq : & ' static WorkQueue ) -> Self {
699
691
Self {
700
692
locked : SpinMutex :: new ( Locked :: new ( count) ) ,
701
693
done : Semaphore :: new ( 0 , 1 ) ,
@@ -812,9 +804,7 @@ impl<'a> BenchTimer<'a> {
812
804
}
813
805
}
814
806
815
- kobj_define ! {
816
- static WORK_STACK : ThreadStack <WORK_STACK_SIZE >;
817
- }
807
+ define_work_queue ! ( WORKQ , WORK_STACK_SIZE , priority = 5 , no_yield = true ) ;
818
808
819
809
static SEMS : [ Semaphore ; NUM_THREADS ] = [ const { Semaphore :: new ( 0 , u32:: MAX ) } ; NUM_THREADS ] ;
820
810
static BACK_SEMS : [ Semaphore ; NUM_THREADS ] = [ const { Semaphore :: new ( 0 , u32:: MAX ) } ; NUM_THREADS ] ;
0 commit comments