This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PRU: atomic exchange,compare-and-swap operations available?

for implementing a queue between CPU and PRU a lock-free algorithm looks attractive

this needs atomic pointer exchange, and compare-and-swap operations

Its clear how to do this on the CPU side - gcc supports these as builtins also for ARM

how would I implement atomic pointer exchange, and compare-and-swap in PRU assembly?

- Michael

  • I probably can answer this to myself..

    for the CPU side, gcc provides the builtins I need (__sync_fetch_and_add () and __sync_sub_and_fetch ()) which use memory barriers to prevent against out-of-order execution

    for the PRU side out-of-order execution is not an issue since it's instruction scheduling is manual (in assembly) to start with and out-of-order execution is not an issue due to the PRU architecture (correct?)

    -Michael

    the lock-free pipe scheme: https://github.com/sustrik/xsnano/blob/master/src/pipe_template.h

    the atomic operations required: https://github.com/sustrik/xsnano/blob/master/src/atomic.h