[linux-audio-dev] lock-free fifos

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: [linux-audio-dev] lock-free fifos
From: Tim Goetze (tim_AT_quitte.de)
Date: Sat May 11 2002 - 16:51:09 EEST


hello all,

i'm evaluating the following construct to implement a lock-free fifo
that allows more than one thread on the writer side:

    inline int return_and_add (int i = 1)
      {
        register int j asm ("eax") = i;

        /* the lock prefix is not strictly needed on
         * single-processor. */
        __asm__ __volatile__ (
            "lock ; xadd %1, %0"
            :"=m" (counter)
            :"ir" (j), "m" (counter));

        return j;
      }

here, the i386 'xadd' instruction atomically adds 'i' to the counter
variable and returns the counter value before the add (obviously this
restricts the fifo size to powers of two so counter overflow can
safely be ignored).

do you happen to know about the availability of an analogon to this
code on other processors than i386?

tia for your thoughts,

tim


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Sat May 11 2002 - 16:47:36 EEST