Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset f1c7755 in mainline for kernel/arch/amd64/include/atomic.h


Ignore:
Timestamp:
2012-08-05T00:12:33Z (9 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master
Children:
b17518e
Parents:
6eaed07
Message:

Added atomic_swap_ptr() for ia32, amd64.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/atomic.h

    r6eaed07 rf1c7755  
    178178}
    179179
     180/** Atomicaly sets *ptr to new_val and returns the previous value. */
     181NO_TRACE static inline void * atomic_swap_ptr(void **pptr, void *new_val)
     182{
     183        void *new_in_old_out = new_val;
     184       
     185        asm volatile (
     186                "xchgq %[val], %[pptr]\n"
     187                : [val] "+r" (new_in_old_out),
     188                  [pptr] "+m" (*pptr)
     189        );
     190       
     191        return new_in_old_out;
     192}
     193
     194/** Sets *ptr to new_val and returns the previous value. NOT smp safe.
     195 *
     196 * This function is only atomic wrt to local interrupts and it is
     197 * NOT atomic wrt to other cpus.
     198 */
     199NO_TRACE static inline void * atomic_swap_ptr_local(void **pptr, void *new_val)
     200{
     201        /*
     202         * Issuing a xchg instruction always implies lock prefix semantics.
     203         * Therefore, it is cheaper to use a cmpxchg without a lock prefix
     204         * in a loop.
     205         */
     206        void *exp_val;
     207        void *old_val;
     208       
     209        do {
     210                exp_val = *pptr;
     211                old_val = atomic_cas_ptr_local(pptr, exp_val, new_val);
     212        } while (old_val != exp_val);
     213       
     214        return old_val;
     215}
     216
     217
    180218#undef _atomic_cas_ptr_impl
    181219
Note: See TracChangeset for help on using the changeset viewer.