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

Changeset f1c7755 in mainline for kernel/arch/ia32/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/ia32/include/atomic.h

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