@@ -8,7 +8,6 @@ extern crate core;
88
99use alloc:: vec:: Vec ;
1010use core:: {
11- ptr:: { addr_of, addr_of_mut, read_volatile, write_volatile} ,
1211 sync:: atomic:: { AtomicUsize , Ordering } ,
1312} ;
1413use user_lib:: { exit, sleep, thread_create, waittid} ;
@@ -44,15 +43,15 @@ unsafe fn eisenberg_enter_critical(id: usize) {
4443 /* announce that we want to enter */
4544 loop {
4645 println ! ( "Thread[{}] try enter" , id) ;
47- write_volatile ( addr_of_mut ! ( FLAG [ id] ) , FlagState :: Want ) ;
46+ vstore ! ( FLAG [ id] , FlagState :: Want ) ;
4847 loop {
4948 /* check if any with higher priority is `Want` or `In` */
5049 let mut prior_thread: Option < usize > = None ;
51- let turn = read_volatile ( addr_of ! ( TURN ) ) ;
50+ let turn = vload ! ( TURN ) ;
5251 let ring_id = if id < turn { id + THREAD_NUM } else { id } ;
5352 // FLAG.iter() may lead to some errors, use for-loop instead
5453 for i in turn..ring_id {
55- if read_volatile ( addr_of ! ( FLAG [ i % THREAD_NUM ] ) ) != FlagState :: Out {
54+ if vload ! ( FLAG [ i % THREAD_NUM ] ) != FlagState :: Out {
5655 prior_thread = Some ( i % THREAD_NUM ) ;
5756 break ;
5857 }
@@ -68,13 +67,13 @@ unsafe fn eisenberg_enter_critical(id: usize) {
6867 sleep ( 1 ) ;
6968 }
7069 /* now tentatively claim the resource */
71- write_volatile ( addr_of_mut ! ( FLAG [ id] ) , FlagState :: In ) ;
70+ vstore ! ( FLAG [ id] , FlagState :: In ) ;
7271 /* enforce the order of `claim` and `conflict check`*/
7372 memory_fence ! ( ) ;
7473 /* check if anthor thread is also `In`, which imply a conflict*/
7574 let mut conflict = false ;
7675 for i in 0 ..THREAD_NUM {
77- if i != id && read_volatile ( addr_of ! ( FLAG [ i] ) ) == FlagState :: In {
76+ if i != id && vload ! ( FLAG [ i] ) == FlagState :: In {
7877 conflict = true ;
7978 }
8079 }
@@ -85,7 +84,7 @@ unsafe fn eisenberg_enter_critical(id: usize) {
8584 /* no need to sleep */
8685 }
8786 /* clain the trun */
88- write_volatile ( addr_of_mut ! ( TURN ) , id) ;
87+ vstore ! ( TURN , id) ;
8988 println ! ( "Thread[{}] enter" , id) ;
9089}
9190
@@ -95,14 +94,14 @@ unsafe fn eisenberg_exit_critical(id: usize) {
9594 let ring_id = id + THREAD_NUM ;
9695 for i in ( id + 1 ) ..ring_id {
9796 let idx = i % THREAD_NUM ;
98- if read_volatile ( addr_of ! ( FLAG [ idx] ) ) == FlagState :: Want {
97+ if vload ! ( FLAG [ idx] ) == FlagState :: Want {
9998 next = idx;
10099 break ;
101100 }
102101 }
103- write_volatile ( addr_of_mut ! ( TURN ) , next) ;
102+ vstore ! ( TURN , next) ;
104103 /* All done */
105- write_volatile ( addr_of_mut ! ( FLAG [ id] ) , FlagState :: Out ) ;
104+ vstore ! ( FLAG [ id] , FlagState :: Out ) ;
106105 println ! ( "Thread[{}] exit, give turn to {}" , id, next) ;
107106}
108107
0 commit comments