Skip to content

Commit

Permalink
[dual_core_demo] use LR/SC spinlock
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed Feb 8, 2025
1 parent f9fc6e5 commit 5210ea6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions sw/example/demo_dual_core/spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static volatile uint32_t __spin_locked = 0;
**************************************************************************/
void spin_lock(void) {

while(__sync_lock_test_and_set(&__spin_locked, -1)); // -> amoswap.w
while(!__sync_bool_compare_and_swap(&__spin_locked, 0, -1)); // -> lr/sc
}


Expand All @@ -26,6 +26,5 @@ void spin_lock(void) {
**************************************************************************/
void spin_unlock(void) {

//__sync_lock_release(&__spin_locked); // uses fence that is not required here
__sync_lock_test_and_set(&__spin_locked, 0); // -> amoswap.w
while(!__sync_bool_compare_and_swap(&__spin_locked, -1, 0)); // -> lr/sc
}

0 comments on commit 5210ea6

Please sign in to comment.