- Timestamp:
- Jan 13, 2014, 3:05:43 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/spin_lock.c
r258 r266 30 30 void lock_acquire(giet_lock_t * lock) { 31 31 unsigned int * plock = &lock->value; 32 unsigned int delay = giet_rand(); 33 34 if (delay == 0) delay++; 32 35 33 36 asm volatile ( 34 "move $16, %0 \n" 35 "giet_lock_try : \n" 36 "ll $2, 0($16) \n" /* $2 <= lock current value */ 37 "bnez $2, giet_lock_delay \n" /* retry if lock already taken */ 38 "li $3, 1 \n" /* $3 <= argument for sc */ 39 "sc $3, 0($16) \n" /* try to get lock */ 40 "bnez $3, giet_lock_ok \n" /* exit if atomic */ 37 "giet_lock_try: \n" 38 "ll $2, 0(%0) \n" /* $2 <= _ioc_lock current value */ 39 "bnez $2, giet_lock_delay \n" /* delay if _ioc_lock already taken */ 40 "li $3, 1 \n" /* $3 <= argument for sc */ 41 "sc $3, 0(%0) \n" /* try to set _ioc_lock */ 42 "bnez $3, giet_lock_ok \n" /* exit if atomic */ 41 43 42 "giet_lock_delay: \n" 43 "jal giet_rand \n" /* giet_rand() system call */ 44 "nop \n" 45 "andi $4, $2, 0xFF \n" /* $4 <= delay < 256 cycles */ 44 "giet_lock_delay: \n" 45 "move $4, %1 \n" /* $4 <= delay */ 46 46 47 "giet_lock_loop: \n" 48 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 49 "beqz $4, giet_lock_loop \n" /* test end delay */ 50 "nop \n" 51 "j giet_lock_try \n" /* retry */ 52 "nop \n" 53 "giet_lock_ok: \n" 47 "giet_lock_loop: \n" 48 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 49 "bnez $4, giet_lock_loop \n" /* test end delay */ 50 "nop \n" 51 "j giet_lock_try \n" /* retry */ 52 "nop \n" 53 54 "giet_lock_ok: \n" 54 55 : 55 :"r"(plock) 56 :"$2", "$3", "$4" , "$16");56 :"r"(plock), "r"(delay) 57 :"$2", "$3", "$4"); 57 58 } 58 59 … … 62 63 ////////////////////////////////////////////////////////////////////////////// 63 64 void lock_release(giet_lock_t * lock) { 64 lock->value = 0; 65 unsigned int * plock = &lock->value; 66 67 asm volatile ( "sync\n" ); // necessary because of the TSAR consistency model 68 *plock = 0; 65 69 } 66 70
Note: See TracChangeset
for help on using the changeset viewer.