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

Changeset 2bcf6c6 in mainline for kernel/arch/ia32/include/atomic.h


Ignore:
Timestamp:
2012-07-27T13:34:48Z (9 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master
Children:
4ec9ea41
Parents:
3bb732b
Message:

Added atomic_cas_ptr() including a sanity test for ia32 and amd64.

File:
1 edited

Legend:

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

    r3bb732b r2bcf6c6  
    113113}
    114114
     115
    115116/** ia32 specific fast spinlock */
    116117NO_TRACE static inline void atomic_lock_arch(atomic_t *val)
     
    142143}
    143144
     145
     146#define _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, prefix) \
     147        asm volatile ( \
     148                prefix " cmpxchgl %[newval], %[ptr]\n" \
     149                : /* Output operands. */ \
     150                /* Old/current value is returned in eax. */ \
     151                [oldval] "=a" (old_val), \
     152                /* (*ptr) will be read and written to, hence "+" */ \
     153                [ptr] "+m" (*pptr) \
     154                : /* Input operands. */ \
     155                /* Expected value must be in eax. */ \
     156                [expval] "a" (exp_val), \
     157                /* The new value may be in any register. */ \
     158                [newval] "r" (new_val) \
     159                : "memory" \
     160        )
     161       
     162/** Atomically compares and swaps the pointer at pptr. */
     163NO_TRACE static inline void * atomic_cas_ptr(void **pptr,
     164        void *exp_val, void *new_val)
     165{
     166        void *old_val;
     167        _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, "lock\n");
     168        return old_val;
     169}
     170
     171/** Compare-and-swap of a pointer that is atomic wrt to local cpu's interrupts.
     172 *
     173 * This function is NOT smp safe and is not atomic with respect to other cpus.
     174 */
     175NO_TRACE static inline void * atomic_cas_ptr_local(void **pptr,
     176        void *exp_val, void *new_val)
     177{
     178        void *old_val;
     179        _atomic_cas_ptr_impl(pptr, exp_val, new_val, old_val, "");
     180        return old_val;
     181}
     182
     183#undef _atomic_cas_ptr_impl
     184
    144185#endif
    145186
Note: See TracChangeset for help on using the changeset viewer.