Atomic swap
Marcel Moolenaar
marcel at xcllnt.net
Thu Aug 7 12:24:28 PDT 2003
On Thu, Aug 07, 2003 at 03:06:33PM -0400, Portante, Peter wrote:
> Marcel,
>
> > atomic_swap_long(volatile long *dst, long val, long *res)
> > {
> > __asm ( "1: ldq_l t0,%0\n"
> > " mov %1,t1\n"
> > " stq_c t1,%0\n"
> > " beq t1,1b\n"
> > " stq t0,%3\n"
^^^^^^^^^^^^^^^^^^^^
Whoops, typo: %3 should be %2.
> > :: "m"(*dst), "r"(val), "m"(*res) : "memory");
> > }
> >
> A word of caution on performing that stq without an MB before it:
> another processor cannot read that location and the destination
> location and assume anything about their contents based on what
> they read unless an MB is between them.
Good point. I don't think we have to worry about it, though. This
function has a specific usage (see src/lib/libpthread/sys/lock.c).
If I understand the code correctly, *res is never used other than
the caller of atomic_swap_long that writes to *res.
--
Marcel Moolenaar USPA: A-39004 marcel at xcllnt.net
More information about the freebsd-alpha
mailing list