Smp recrsive spinlock confusion in RP2040

I am trying to port freertos smp and reference RP2040

I have confusion about acquiring lock:

        if( uxAcquire )
            if( __builtin_expect( !*pxSpinLock, 0 ) )
                if( ucOwnedByCore[ulCoreNum] & ulLockBit )
                    configASSERT(ucRecursionCountByLock[ulLockNum] != 255u );
                while ( __builtin_expect( !*pxSpinLock, 0 ) );
            configASSERT(ucRecursionCountByLock[ulLockNum] == 0 );
             /* there needs a operation to mark the pxSpinLock? */
            ucRecursionCountByLock[ulLockNum] = 1;
            ucOwnedByCore[ulCoreNum] |= ulLockBit;

When a task acquires lock successfully,it should change ‘ pxSpinLock’ value to 0 to indicating the lock is acquired.

Besides, I do not think this spinlock implement is mutual exclusion.

Best regards

You do not need to do that explicitly as these are hardware spin locks. Look at the hardware spinlocks section in the datasheet.

Would you please elaborate your thinking.

1 Like

Thank you for your reply.

The spinlock from RP2040 is implemented by hardwire. I thought if is is implemented by soft, it may require mutual exclusion operation to ensure atomic.