This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

InterlockedExchangeAdd equivalent

Note: This was originally posted on 11th February 2013 at http://forums.arm.com

I'm porting a Windows application to an ARM® Cortex-A9 based system running Ubuntu 12.04 and I need something equivalent the Windows function InterlockedExchangeAdd().  Is there a function like this available for ARM?  If not, can anyone provide some equivalent assembly code?
Parents
  • Note: This was originally posted on 14th February 2013 at http://forums.arm.com


    It depends what you are using it for TBH. If you are using it like a spinlock (e.g., incref to lock, decref to unlock) then you need barriers after the lock before you touch the memory it is protecting (ensure that the lock is committed before other instructions in the instruction stream can touch the memory) and before the unlock (ensure you've committed data it is protecting to memory before you release the lock). If you don't then you risk race conditions and trampled data (and much painful debugging - trust me).

    If you are just using it like a reference count then you might get away with it ;)


    The purpose is to provide a multi-thread safe increment / decrement of an integer value.  It's primary use is for reference counting, but it may also be used for other "counting" operations.  Based on your second comment then, it sounds like I can eliminate the use of barriers altogether.
Reply
  • Note: This was originally posted on 14th February 2013 at http://forums.arm.com


    It depends what you are using it for TBH. If you are using it like a spinlock (e.g., incref to lock, decref to unlock) then you need barriers after the lock before you touch the memory it is protecting (ensure that the lock is committed before other instructions in the instruction stream can touch the memory) and before the unlock (ensure you've committed data it is protecting to memory before you release the lock). If you don't then you risk race conditions and trampled data (and much painful debugging - trust me).

    If you are just using it like a reference count then you might get away with it ;)


    The purpose is to provide a multi-thread safe increment / decrement of an integer value.  It's primary use is for reference counting, but it may also be used for other "counting" operations.  Based on your second comment then, it sounds like I can eliminate the use of barriers altogether.
Children
No data