Changeset 345 for soft/giet_vm/giet_libs/barrier.c
- Timestamp:
- Jun 25, 2014, 2:19:37 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/barrier.c
r295 r345 20 20 unsigned int value ) 21 21 { 22 barrier->init = value; 23 barrier->count = value; 22 barrier->init = (volatile unsigned int)value; 23 barrier->count = (volatile unsigned int)value; 24 asm volatile ("sync" ::: "memory"); 24 25 } 25 26 … … 31 32 void barrier_wait( giet_barrier_t* barrier ) 32 33 { 33 unsigned int * pcount= (unsigned int *) &barrier->count;34 unsigned int maxcount = barrier->init;35 unsigned int count;34 volatile unsigned int * pcount = (unsigned int *) &barrier->count; 35 volatile unsigned int maxcount = barrier->init; 36 volatile unsigned int count; 36 37 37 38 // parallel decrement barrier counter using atomic instructions LL/SC 38 39 // - input : pointer on the barrier counter 39 40 // - output : counter value 40 asm volatile ("_barrier_decrement: \n" 41 "ll %0, 0(%1) \n" 42 "addi $3, %0, -1 \n" 43 "sc $3, 0(%1) \n" 44 "beqz $3, _barrier_decrement \n" 45 : "=&r"(count) 41 asm volatile ( 42 "_barrier_decrement: \n" 43 "ll %0, 0(%1) \n" 44 "addi $3, %0, -1 \n" 45 "sc $3, 0(%1) \n" 46 "beqz $3, _barrier_decrement \n" 47 : "+r"(count) 46 48 : "r"(pcount) 47 : "$ 2", "$3");49 : "$3", "memory"); 48 50 49 51 // the last task re-initializes the barrier counter to the max value, … … 57 59 else { 58 60 // other tasks busy-wait 59 while (*pcount != maxcount) asm volatile ("nop");61 while (*pcount != maxcount); 60 62 } 63 64 asm volatile ("sync" ::: "memory"); 61 65 } 62 66
Note: See TracChangeset
for help on using the changeset viewer.