Changeset 228 for soft/giet_vm/libs/spin_lock.c
- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/libs/spin_lock.c
r189 r228 28 28 // If the lock is already taken a random delay is introduced before retry. 29 29 /////////////////////////////////////////////////////////////////////////////////// 30 void lock_acquire( giet_lock_t* lock ) 31 { 32 unsigned int* plock = &lock->value; 33 30 void lock_acquire(giet_lock_t * lock) { 31 unsigned int * plock = &lock->value; 32 34 33 asm volatile ( 35 "giet_lock_try: 36 "ll $2, 0(%0) 37 "bnez $2, giet_lock_delay 38 "li $3, 1 39 "sc $3, 0(%0) 40 "bnez $3, giet_lock_ok 34 "giet_lock_try: \n" 35 "ll $2, 0(%0) \n" /* $2 <= lock current value */ 36 "bnez $2, giet_lock_delay \n" /* retry if lock already taken */ 37 "li $3, 1 \n" /* $3 <= argument for sc */ 38 "sc $3, 0(%0) \n" /* try to get lock */ 39 "bnez $3, giet_lock_ok \n" /* exit if atomic */ 41 40 42 "giet_lock_delay: 43 "jal giet_rand 44 "nop 45 "andi $4, $2, 0xFF \n"/* $4 <= delay < 256 cycles */41 "giet_lock_delay: \n" 42 "jal giet_rand \n" /* giet_rand() system call */ 43 "nop \n" 44 "andi $4, $2, 0xFF \n" /* $4 <= delay < 256 cycles */ 46 45 47 "giet_lock_loop: 48 "addi $4, $4, -1 49 "beqz $4, giet_lock_loop 50 "nop 51 "j giet_lock_try 52 "nop 53 "giet_lock_ok: 46 "giet_lock_loop: \n" 47 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 48 "beqz $4, giet_lock_loop \n" /* test end delay */ 49 "nop \n" 50 "j giet_lock_try \n" /* retry */ 51 "nop \n" 52 "giet_lock_ok: \n" 54 53 : 55 54 :"r"(plock) 56 55 :"$2", "$3", "$4"); 57 } 56 } 57 58 58 59 59 ////////////////////////////////////////////////////////////////////////////// 60 60 // lock_release() 61 61 ////////////////////////////////////////////////////////////////////////////// 62 void lock_release( giet_lock_t* lock) 63 { 62 void lock_release(giet_lock_t * lock) { 64 63 lock->value = 0; 65 64 } 66 65 66 67 // Local Variables: 68 // tab-width: 4 69 // c-basic-offset: 4 70 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 71 // indent-tabs-mode: nil 72 // End: 73 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 74
Note: See TracChangeset
for help on using the changeset viewer.