[zeromq-dev] rc == 0 (./zmq/mutex.hpp:94)
Martin Sustrik
sustrik at fastmq.com
Tue Jul 14 11:48:13 CEST 2009
Steven McCoy wrote:
> 2009/7/14 Aamir M <aamirjvm at gmail.com <mailto:aamirjvm at gmail.com>>
>
> You could potentially use
> a PlayStation3 with Linux to do the testing ... PS3 is a relatively
> cheap PowerPC environment, though setting up the build environment
> might be a pain.
>
>
> Easier to find an old Mac to use, I have a G3 sitting idle but it's
> rather slow. Of course you can just lift the tried and tested PowerPC
> assembly from glibc, noting there appears to be a compiler bug
> when optimizing:
We cannot use glib code directly as LGPL would prevent our customers to
make commercial (closed source) versions of 0MQ. Anyway, the code below
demonstrates that atomic ops are relatively easy to implement.
Martin
>
> #if defined (G_ATOMIC_POWERPC)
> /* Adapted from CVS version 1.16 of glibc's sysdeps/powerpc/bits/atomic.h
> * and CVS version 1.4 of glibc's sysdeps/powerpc/powerpc32/bits/atomic.h
> * and CVS version 1.7 of glibc's sysdeps/powerpc/powerpc64/bits/atomic.h
> */
> # ifdef __OPTIMIZE__
> /* Non-optimizing compile bails on the following two asm statements
> * for reasons unknown to the author */
> gint
> g_atomic_int_exchange_and_add (volatile gint *atomic,
> gint val)
> {
> gint result, temp;
> __asm__ __volatile__ ("1: lwarx %0,0,%3\n"
> " add %1,%0,%4\n"
> " stwcx. %1,0,%3\n"
> " bne- 1b"
> : "=&b" (result), "=&r" (temp), "=m" (*atomic)
> : "b" (atomic), "r" (val), "m" (*atomic)
> : "cr0", "memory");
> return result;
> }
>
> /* The same as above, to save a function call repeated here */
> void
> g_atomic_int_add (volatile gint *atomic,
> gint val)
> {
> gint result, temp;
> __asm__ __volatile__ ("1: lwarx %0,0,%3\n"
> " add %1,%0,%4\n"
> " stwcx. %1,0,%3\n"
> " bne- 1b"
> : "=&b" (result), "=&r" (temp), "=m" (*atomic)
> : "b" (atomic), "r" (val), "m" (*atomic)
> : "cr0", "memory");
> }
> # else /* !__OPTIMIZE__ */
> gint
> g_atomic_int_exchange_and_add (volatile gint *atomic,
> gint val)
> {
> gint result;
> do
> result = *atomic;
> while (!g_atomic_int_compare_and_exchange (atomic, result, result + val));
>
> return result;
> }
>
> void
> g_atomic_int_add (volatile gint *atomic,
> gint val)
> {
> gint result;
> do
> result = *atomic;
> while (!g_atomic_int_compare_and_exchange (atomic, result, result + val));
> }
> # endif /* !__OPTIMIZE__ */
>
> # if GLIB_SIZEOF_VOID_P == 4 /* 32-bit system */
> gboolean
> g_atomic_int_compare_and_exchange (volatile gint *atomic,
> gint oldval,
> gint newval)
> {
> gint result;
> __asm__ __volatile__ ("sync\n"
> "1: lwarx %0,0,%1\n"
> " subf. %0,%2,%0\n"
> " bne 2f\n"
> " stwcx. %3,0,%1\n"
> " bne- 1b\n"
> "2: isync"
> : "=&r" (result)
> : "b" (atomic), "r" (oldval), "r" (newval)
> : "cr0", "memory");
> return result == 0;
> }
>
> gboolean
> g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic,
> gpointer oldval,
> gpointer newval)
> {
> gpointer result;
> __asm__ __volatile__ ("sync\n"
> "1: lwarx %0,0,%1\n"
> " subf. %0,%2,%0\n"
> " bne 2f\n"
> " stwcx. %3,0,%1\n"
> " bne- 1b\n"
> "2: isync"
> : "=&r" (result)
> : "b" (atomic), "r" (oldval), "r" (newval)
> : "cr0", "memory");
> return result == 0;
> }
> # elif GLIB_SIZEOF_VOID_P == 8 /* 64-bit system */
> gboolean
> g_atomic_int_compare_and_exchange (volatile gint *atomic,
> gint oldval,
> gint newval)
> {
> gpointer result;
> __asm__ __volatile__ ("sync\n"
> "1: lwarx %0,0,%1\n"
> " extsw %0,%0\n"
> " subf. %0,%2,%0\n"
> " bne 2f\n"
> " stwcx. %3,0,%1\n"
> " bne- 1b\n"
> "2: isync"
> : "=&r" (result)
> : "b" (atomic), "r" (oldval), "r" (newval)
> : "cr0", "memory");
> return result == 0;
> }
>
> gboolean
> g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic,
> gpointer oldval,
> gpointer newval)
> {
> gpointer result;
> __asm__ __volatile__ ("sync\n"
> "1: ldarx %0,0,%1\n"
> " subf. %0,%2,%0\n"
> " bne 2f\n"
> " stdcx. %3,0,%1\n"
> " bne- 1b\n"
> "2: isync"
> : "=&r" (result)
> : "b" (atomic), "r" (oldval), "r" (newval)
> : "cr0", "memory");
> return result == 0;
> }
> # else /* What's that */
> # error "Your system has an unsupported pointer size"
> # endif /* GLIB_SIZEOF_VOID_P */
>
> --
> Steve-o
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list