pkarashchenko commented on issue #6569:
URL:
https://github.com/apache/incubator-nuttx/issues/6569#issuecomment-1173733406
@xiaoxiang781216 the issue is that currently it is implemented as you
pointed, but it use `lr`/`sc`, but I posted an issue that we can rework it to
use `amoswap`.
Current code:
```
.globl up_testset
.type up_testset, %function
up_testset:
li a1, SP_LOCKED
/* Test if the spinlock is locked or not */
retry:
LR_INST a2, (a0) /* Test if spinlock is locked or not */
beq a2, a1, locked /* Already locked? Go to locked: */
/* Not locked ... attempt to lock it */
SC_INST a2, a1, (a0) /* Attempt to set the locked state (a1) to (a0) */
bnez a2, retry /* a2 will not be zero, if sc.b failed, try again
*/
/* Lock acquired -- return SP_UNLOCKED */
fence /* Required before accessing protected resource */
li a0, SP_UNLOCKED
jr ra
/* Lock not acquired -- return SP_LOCKED */
locked:
li a0, SP_LOCKED
jr ra
.size up_testset, . - up_testset
.end
```
But can be something like
```
.globl up_testset
.type up_testset, %function
up_testset:
li a1, SP_LOCKED
amoswap.w a2, a1, (a0) /* Attempt to acquire spinlock atomically */
beq a2, a1, locked /* Already locked? Go to locked: */
/* Lock acquired -- return SP_UNLOCKED */
fence /* Required before accessing protected resource */
li a0, SP_UNLOCKED
jr ra
/* Lock not acquired -- return SP_LOCKED */
locked:
li a0, SP_LOCKED
jr ra
.size up_testset, . - up_testset
.end
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]