@@ -13,7 +13,6 @@ extern crate alloc;
13
13
#[ allow( unused_imports) ]
14
14
use alloc:: boxed:: Box ;
15
15
use alloc:: vec:: Vec ;
16
- use zephyr:: sys:: thread:: Thread ;
17
16
use zephyr:: time:: { Duration , sleep, Tick } ;
18
17
use zephyr:: {
19
18
printkln,
@@ -63,19 +62,10 @@ extern "C" fn rust_main() {
63
62
let syncers = get_syncer ( ) ;
64
63
65
64
printkln ! ( "Pre fork" ) ;
66
- // At this time, the arrays of threads are not supported, so manually unroll the loop for now.
67
- // If NUM_PHIL is changed, this loop and the declarations at the end will have to be updated.
68
- let threads: [ Thread ; NUM_PHIL ] = [
69
- PHIL_THREAD_1 . init_once ( PHIL_STACK_1 . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ,
70
- PHIL_THREAD_2 . init_once ( PHIL_STACK_2 . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ,
71
- PHIL_THREAD_3 . init_once ( PHIL_STACK_3 . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ,
72
- PHIL_THREAD_4 . init_once ( PHIL_STACK_4 . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ,
73
- PHIL_THREAD_5 . init_once ( PHIL_STACK_5 . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ,
74
- PHIL_THREAD_6 . init_once ( PHIL_STACK_6 . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ,
75
- ] ;
76
65
77
66
for ( i, syncer) in ( 0 ..NUM_PHIL ) . zip ( syncers. into_iter ( ) ) {
78
- threads[ i] . spawn ( move || {
67
+ let thread = PHIL_THREADS [ i] . init_once ( PHIL_STACKS [ i] . init_once ( ( ) ) . unwrap ( ) ) . unwrap ( ) ;
68
+ thread. spawn ( move || {
79
69
phil_thread ( i, syncer) ;
80
70
} ) ;
81
71
}
@@ -139,17 +129,6 @@ fn get_random_delay(id: usize, period: usize) -> Duration {
139
129
}
140
130
141
131
kobj_define ! {
142
- static PHIL_THREAD_1 : StaticThread ;
143
- static PHIL_THREAD_2 : StaticThread ;
144
- static PHIL_THREAD_3 : StaticThread ;
145
- static PHIL_THREAD_4 : StaticThread ;
146
- static PHIL_THREAD_5 : StaticThread ;
147
- static PHIL_THREAD_6 : StaticThread ;
148
-
149
- static PHIL_STACK_1 : ThreadStack <PHIL_STACK_SIZE >;
150
- static PHIL_STACK_2 : ThreadStack <PHIL_STACK_SIZE >;
151
- static PHIL_STACK_3 : ThreadStack <PHIL_STACK_SIZE >;
152
- static PHIL_STACK_4 : ThreadStack <PHIL_STACK_SIZE >;
153
- static PHIL_STACK_5 : ThreadStack <PHIL_STACK_SIZE >;
154
- static PHIL_STACK_6 : ThreadStack <PHIL_STACK_SIZE >;
132
+ static PHIL_THREADS : [ StaticThread ; NUM_PHIL ] ;
133
+ static PHIL_STACKS : [ ThreadStack <PHIL_STACK_SIZE >; NUM_PHIL ] ;
155
134
}
0 commit comments